1. 程式人生 > >Android studio jar衝突 檔案衝突 aar引用相同的檔案 引用相同的jar包 重複匯入相同依賴包

Android studio jar衝突 檔案衝突 aar引用相同的檔案 引用相同的jar包 重複匯入相同依賴包

       開發專案,多多少少都會引進一些第三方jar或者aar資原始檔,方便開發個性化功能,但這樣就經常會出現包衝突、檔案衝突、重複匯入資源或者匯入倆個不同的包中包含有相同的檔案資源呢!後果導致編譯失敗,提示錯誤!
下面就來加講解下我遇到問題及解決方法:

1. 檔案衝突

檔案錯誤提示

       一般類似這樣的Error:Execution failed for task ‘:app:transformResourcesWithMergeJavaResForDebug’.> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup.okio/okio/pom.xml File1: C:\Users\WX_JIN.gradle\caches\modules-2\files-2.1\com.squareup.okio\okio\1.6.0\98476622f10715998eacf9240d6b479f12c66143\okio-1.6.0.jar File2: D:\Android\workspace\wxj\YK\app\build\intermediates\exploded-aar\YK\umenglibrary\unspecified\jars\classes.jar
上面提示Duplicate files copied in APK META-INF/maven/com.squareup.okio/okio/pom.xml
重複這個檔案,我們只要去掉一個或者忽略一個就行了
提示錯誤類似這個

解決方案

       在主專案中新增build->android->新增packagingOptions exclude 包含重複的檔案
解決方案截圖

2. jar衝突

衝突提示

錯誤提示

解決方案

解決一
解決二
使用上面這種忽略掉重複的依賴包