1. 程式人生 > >Android--Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

Android--Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

FAILURE: Build failed with an exception.

* What went wrong:
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\82661\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.2.0\42bfaf64c94f3848ebf5cf1c2ea4ec9d1b3ac6c8\rxjava-1.2.0.jar
	File2: D:\ThoughtCode\Android-code\YunHealth\app\build\intermediates\exploded-aar\cn.bmob.android\bmob-sdk\3.5.0\jars\classes.jar


* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

解決辦法:

1.在Gradle:app中加入程式碼:

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

插入後Gradle如下:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '24.0.0'
    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    defaultConfig {
        applicationId "wang.fly.com.yunhealth"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories{
    flatDir{
        dirs 'libs' //存放aar的目錄地址
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile name: 'SMSSDK-2.1.2', ext: 'aar'
    compile name: 'SMSSDKGUI-2.1.2', ext: 'aar'
    testCompile 'junit:junit:4.12'
    //3.5.0:請務必檢視下面註釋[1]
    compile 'cn.bmob.android:bmob-sdk:3.5.0'
    //如果你想應用能夠相容Android6.0,請新增此依賴(org.apache.http.legacy.jar)
    compile 'cn.bmob.android:http-legacy:1.0'
    //配置Mob簡訊驗證
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:recyclerview-v7:25.0.+'
    compile 'io.reactivex:rxjava:1.2.0'
    compile 'io.reactivex:rxandroid:1.2.0'
    compile files('libs/MobCommons-2016.1012.1447.jar')
    compile files('libs/MobTools-2016.1012.1447.jar')
}

解決結果:對我無效

2.解決依賴衝突

手動匯入了Bmob第三方依賴,並將衝突的依賴檔案刪除(據此應該可以嘗試使用gradle依賴,將rxjava包的最新版匯入)

參考博文:

Gradle依賴項學習總結,dependencies、transitive、force、exclude的使用與依賴衝突解決 | Paincker | Hacker Meets Painter
http://www.paincker.com/gradle-dependencies

解決結果:成功