Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
阿新 • • 發佈:2019-02-17
下午好,今天來看看我遇到的一個問題(錯誤如下):
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
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/rxjava.properties File1: C:\Users\pc\.gradle\daemon\gradle-2.8\wrapper\dists\gradle-3.3-all\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.5\ece7b5d0870e66d8226dab6dcf47a2b12afff061\rxjava-1.1.5.jar File2: C:\Users\pc\.gradle\daemon\gradle-2.8\wrapper\dists\gradle-3.3-all\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.7\21734c0092a5d3c3ec99510e50c1ff76bdf0c65a\rxjava-2.0.7.jar
這是一個關於rxjava包衝突的錯誤,也就是說,我們匯入了兩個不同版本的rxjava的包而導致的,IDE可能是無法自己選擇某一個從而導致的一個衝突,廢話不多說,直接看看怎麼解決:
android { compileSdkVersion rootProject.ext.android["compileSdkVersion"] buildToolsVersion rootProject.ext.android["buildToolsVersion"] useLibrary 'org.apache.http.legacy' compileOptions { targetCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "me.jessyan.mvparms.demo" minSdkVersion rootProject.ext.android["minSdkVersion"] targetSdkVersion rootProject.ext.android["targetSdkVersion"] versionCode rootProject.ext.android["versionCode"] versionName rootProject.ext.android["versionName"] testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"] } buildTypes { debug { buildConfigField "boolean", "LOG_DEBUG", "true" buildConfigField "boolean", "USE_CANARY", "true" minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { buildConfigField "boolean", "LOG_DEBUG", "false" buildConfigField "boolean", "USE_CANARY", "false" minifyEnabled true shrinkResources true zipAlignEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions{ exclude 'META-INF/rxjava.properties' exclude 'META-INF/NOTICE' // will not include NOTICE file exclude 'META-INF/LICENSE' // will not include LICENSE file // as noted by @Vishnuvathsan you may also need to include // variations on the file name. It depends on your dependencies. // Some other common variations on notice and license file names exclude 'META-INF/notice' exclude 'META-INF/notice.txt' exclude 'META-INF/license' exclude 'META-INF/license.txt' } lintOptions { disable 'InvalidPackage' disable "ResourceType" abortOnError false } } buildscript { repositories { jcenter() } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') //support compile(rootProject.ext.dependencies["cardview-v7"]) { exclude module: 'support-annotations' } //tools annotationProcessor rootProject.ext.dependencies["dagger2-compiler"] compile rootProject.ext.dependencies["progressmanager"] compile rootProject.ext.dependencies["retrofit-url-manager"] provided rootProject.ext.dependencies["javax.annotation"]//dagger2必須依賴jsr250 annotation //view annotationProcessor(rootProject.ext.dependencies["butterknife-compiler"]) { exclude module: 'support-annotations' exclude module: 'butterknife-annotations' } compile rootProject.ext.dependencies["paginate"] //arms compile project(':arms') // compile 'me.jessyan:arms:2.2.3' //test testCompile rootProject.ext.dependencies["junit"] debugCompile rootProject.ext.dependencies["canary-debug"] releaseCompile rootProject.ext.dependencies["canary-release"] testCompile rootProject.ext.dependencies["canary-release"] compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile 'com.google.code.gson:gson:2.3' compile 'com.squareup.retrofit:retrofit:2.0.0-beta1' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' // compile 'io.reactivex:rxjava:1.1.0' compile 'io.reactivex:rxandroid:1.1.0' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' compile 'com.squareup.retrofit2:converter-scalars:2.1.0' compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' }
上面是我的build.gradle檔案,大家可以看看新增的程式碼放在什麼位置,下面是我所新增的程式碼,來看看吧:
packagingOptions{ exclude 'META-INF/rxjava.properties' exclude 'META-INF/NOTICE' // will not include NOTICE file exclude 'META-INF/LICENSE' // will not include LICENSE file // as noted by @Vishnuvathsan you may also need to include // variations on the file name. It depends on your dependencies. // Some other common variations on notice and license file names exclude 'META-INF/notice' exclude 'META-INF/notice.txt' exclude 'META-INF/license' exclude 'META-INF/license.txt' }
我的錯誤是匯入了兩個rxjava的不同版本的包導致的,因為IDE好像無法從兩個包裡去選擇一個來用,從而導致了依賴包的衝突,所以除了rxjava的衝突還有可能在我們導依賴包的時候出現其他的包的衝突,這都要在packagingOptions裡新增對應的過濾,新增這句是用來濾檔案配置的,我的錯誤解決是新增下面一句rxjava的過濾程式碼:
exclude 'META-INF/rxjava.properties'
OK,再也不用擔心重新來過啦,希望對大家有所幫助,謝謝!