프로젝트 전체 참조 상수 관리

suee97·2022년 3월 21일
0

일반적으로 프로젝트 전체가 참조하는 상수는 프로젝트 모듈의 build gradle 파일에서 관리함

기존방식

dependencies {
    def navVersion = "2.4.1"

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation "androidx.navigation:navigation-fragment-ktx:$navVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navVersion"
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

일반적으로 앱모듈 단에서 navVersion이라는 버전 정보를 관리함
이렇게 해도 상관은 없을 것 같은데 어쨋든 다른 곳에서 참조할 수 있도록 하는 것이 좋음

변경방식

def navVersion = "2.4.1"

이 부분을 지우고 프로젝트 모듈의 build gradle 파일로 이동

// buildscript...
ext {
    navVersion = '2.4.1'
}
// task clean...

다음과 같은 블럭을 추가
이후 sync now를 클릭해서 동기화 시켜주면 끝!


출처
https://www.udemy.com/course/learn-android-development-with-kotlin/
https://developer.android.com/guide/navigation/navigation-getting-started?hl=ko#groovy

profile
승언

0개의 댓글