close

Android 可以用 Android Studio build 到手機、模擬器運行

也可以用指令 ./gradlew assemble 來 build apk 檔

前者的檢查似忽會比較寬鬆,就算可以正常運行了

後者也可能會 build 不過 ( 如 string.xml 的 error…等 )

string.xml 的事比較好解決,今天要說的是下面的 issue


> Task :app:lintVitalProductionRelease
Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
 

 

這個 error 其實關鍵就在 commons-logging & httpclient

意思就是這個庫重複了

但麻煩在於,他包在其它引入 third party library 裡面

我們怎麼知道是哪個 library 導致的呢?

 

其實還有一個指令

./gradlew app:dependencies

執行後會有所有的 dependencies 的 dependncies 的 dependencies  XD

在裡面找到 commons-logging 就可以了

載取找到的部份

+--- com.google.api-client:google-api-client-gson:1.22.0
        |    +--- com.google.api-client:google-api-client:1.22.0
        |    |    +--- com.google.oauth-client:google-oauth-client:1.22.0
        |    |    |    +--- com.google.http-client:google-http-client:1.22.0
        |    |    |    |    +--- com.google.code.findbugs:jsr305:1.3.9
        |    |    |    |     --- org.apache.httpcomponents:httpclient:4.0.1
        |    |    |    |         +--- org.apache.httpcomponents:httpcore:4.0.1
        |    |    |    |         +--- commons-logging:commons-logging:1.1.1
        |    |    |    |          --- commons-codec:commons-codec:1.3

 

既然知道了是哪一個就好處理了

在 build.gradle 裡面 exclude 就好

implementation('com.google.api-client:google-api-client-gson:1.22.0', {
    exclude 
           group: 'org.apache.httpcomponents'
           , module: 'httpclient'
})

 

這段的意思是 implenentaion 這個庫

但是排除裡面的 httpclient

由於 commons-logging 是包在 httpclient 裡面的

所以只要 exculde httpclient 就可以囉

 

 

 

 

資料:

https://stackoverflow.com/questions/47337218/error-duplicateplatformclasses-class-conflict-when-building-release-on-room-pe
 

 

 

 


arrow
arrow

    顏澤偉 發表在 痞客邦 留言(0) 人氣()