안드로이드 개발 팁 #81 - Android API 타겟 버전 34로 상향 후, 추가 수정할 사항들

Android API 타겟 버전 34로 상향 후, 추가 수정할 사항들

No. 81
2024. 08. 09 (금) | Written by @dorian-mobileapp

시작하며...

구글에서 강제로 Android API 타겟 버전을 34로 올리라는 공지를 받았습니다. 회사의 기존 앱들 중 일부는 내리고 나머지들에 이를 적용하기로 했습니다. 이게 생각보다 쉽지는 않은 작업이었습니다. 추가로 수정해야 할 사항들이 의외로 많았기 때문이지요. 나중에 시행착오를 반복하지 않기 위해 이번 포스트에 내용 정리를 합니다.

참고로 2024년 8월 9일 기준으로 작성했습니다. 수정할 사항들은 시간이 지나면 변경 또는 추가될 수 있습니다.


Android API 타겟 버전 34로 상향 후, 추가 수정할 사항들

  • 프로젝트의 build.gradle 파일
  • 모듈의 build.gradle 파일
  • gradle.properties 파일
  • gradle-wrapper.properties 파일

프로젝트의 build.gradle 파일

  • dependencies 블록의 gradle 버전을 8.x.x로 올리기
plugins {
    id 'com.android.application' version '8.3.2' apply false
    id 'com.android.library' version '8.3.2' apply false
    // ...
}

또는

buildscript {
    // ...

    dependencies {
        classpath "com.android.tools.build:gradle:8.3.2"
        // ...
    }
}
  • Kotlin 버전 1.8 이상으로 설정
plugins {
    // ...
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

또는

buildscript {
    // ...

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
        // ...
    }
}

모듈의 build.gradle 파일

  • android 블록에 namespace 추가
    • namespace: 앱 패키지와 동일
android {
    namespace "(앱 패키지와 동일)"
    // ...
}
  • 자바 버전 1.8에서 17로 변경
android {
    // ...

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        freeCompilerArgs = ['-Xjvm-default=enable']
        jvmTarget = '17'
    }

    // ...
}
  • androidx에 속하는 라이브러리 버전 업
    • 일단 수정하지 않고 빌드 시도해보고, 빌드 오류 확인 후 수정
    • 수정시 안드로이드 스튜디오가 자동으로 권장하는 버전으로 설정하면 무난 (2024. 8. 9 기준)

gradle.properties 파일

  • android.nonFinalResIds 속성을 false로 설정
    • 기존 자바 코드의 switch 문에서 case의 값이 리소스 ID이면, 빌드 오류 발생하기 때문
android.nonFinalResIds = false

gradle-wrapper.properties 파일

  • distributionUrl에서 파일 이름 변경
    • 이전: gradle-7.x-bin.zip (7.x 이하의 버전)
    • 변경: gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip

지난 안드로이드 개발 팁


Layout provided by Steemit Enhancer hommage by ayogom


Posted through the ECblog app (https://blog.etain.club)
Sort:  

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.05
TRX 0.33
JST 0.080
BTC 63398.51
ETH 1702.04
USDT 1.00
SBD 0.41