본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] Dependency conflict 해결하기

by 돼지왕 왕돼지 2018. 3. 15.
반응형


All, Android, build variable, Configurations, dependency, dependency check, dependency conflict, exclude, explit compile, Force, gradlew dependencies, library version, resolutionstrategy, [android] Dependency conflict 해결하기, 해결 방법


-

아래 명령을 통해 dependency 와 그 버전을 확인 할 수 있다.

만약 2개의 library 가 같은 lib 그러나 version 이 다른 dependency 를 가지고 있다면 highest dependency 를 가져간다.

./gradlew dependencies



-

같은 build variable 에 대해 공통의 dependency 가 있다면 위의 규칙을 따르지만,

다른 build variable 에 대해서는 dependency conflict 가 발생 할 수 있다.

예를 들면 compile 과 androidTestCompile 에 사용되는 lib 이 다른 version 을 가르킬 때이다.


이 경우 다음과 같이 dependency 를 제거할 수 있다.


1. 한 dependency 에서 conflict 가 나는 module 이나 library 를 제거한다.

compile (‘jnuit:jnuit:4.12’) { // groupName : moduleName : version

    exclude group:’org.hamcrest’, module:’hamcrest-core'

}



2. conflict 나는 library 를 explicit 하게 define 해준다.

compile 'junit:junit:4.12' // Depends on version org.hamcrest:hamcrest-core 1.3

androidTestCompile 'org.mockito:mockito-core:1.10.19' // Depends on version org.hamcrest:hamcrest-core 1.1

androidTestCompile 'org.hamcrest:hamcrest-core:1.3' // explicitly mention 


이 방법은 conflict 나는 lib 을 업데이트해줄 때 dependency conflict 가 낫던 library version 역시 함께 조정해줘야 한다.




3. 해당 library 를 모든 version 에 대해 해결해준다.

android{

    configurations.all{

        resolutionStrategy.force ‘org.hamcrest:hamcrest-core:1.1'

    }

}


단 이 방법은 모든 버전에 적용되기 때문에 2번 방법보다 conflict 해결은 쉽지만, library version update 에 더 취약하다.



참고 링크

https://blog.mindorks.com/avoiding-conflicts-in-android-gradle-dependencies-28e4200ca235#.hcki8610v





반응형

댓글