当我建立我的应用程序,我得到以下错误:

错误:执行失败任务':app:transformResourcesWithMergeJavaResForDebug'。 在OS独立路径'META-INF/LICENSE'中发现了多个文件

这是我的身材。gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "cn.sz.cyrus.kotlintest"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions{
            annotationProcessorOptions{
                includeCompileClasspath = true
            }
        }
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
 /*       exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'*/
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    compile 'com.github.GrenderG:Toasty:1.2.5'
    compile 'com.orhanobut:logger:1.15'

    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.umeng.analytics:analytics:latest.integration'
    compile 'ai.api:libai:1.4.8'
    compile 'ai.api:sdk:2.0.5@aar'
// api.ai SDK dependencies
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'commons-io:commons-io:2.4'
    compile 'com.android.support:multidex:1.0.1'
}

当我将此代码添加到我的构建时。gradle文件,

  packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }

这个错误将得到解决,但另一个问题将发生。是这样的:

java.lang.NoClassDefFoundError: com.squareup.leakcanary.internal.HeapAnalyzerService
at com.squareup.leakcanary.LeakCanary.isInAnalyzerProcess(LeakCanary.java:145)
at cn.sz.cyrus.wemz.TestApplication.onCreate(TestApplication.kt:32)

谁有办法解决这个问题?


当前回答

这发生在使用

org.jetbrains.kotlinx: kotlinx-coroutines-core: 1.2.0

并在下一个版本中修复

org.jetbrains.kotlinx: kotlinx-coroutines-core: 1.2.1

其他回答

我遇到过这个问题,首先是一些本地库(。文件),然后是java/kotlin文件。结果我从源代码中包含了一个库,并通过传递依赖项引用了artifactory。检查您的依赖项树,看看是否有多余的条目。使用./gradlew:app:dependencies获取依赖树。如果主模块名称不同,则将“app”替换为您的模块名称。

我在多模块应用程序环境中也遇到过类似的问题:

错误:任务执行失败 “应用程序:transformResourcesWithMergeJavaResForDebug”。多个文件 发现OS独立路径'META-INF/AL2.0'

我的几个模块报告了这个问题,上面的解决方案都没有解决它。 事实证明,我使用的是Coroutines 1.3.6版本,它似乎嵌入了META-INF/AL2.0,而我使用的另一个库已经嵌入了META-INF/AL2.0。为了解决这个问题,我向构建中添加了以下代码片段。失败模块的Gradle:

configurations.all {
    resolutionStrategy {
        exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"

    }
}

鉴于它发生在多个模块上,我已经将resolutionStrategy代码移动到我的项目级别build.gradle。 从那以后一切都正常了。

如果你有这个问题,你有一个gradle .jar依赖,像这样:

implementation group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26'

间隔版本,直到一个匹配并解决异常,并应用此线程的最佳答案。

我将Studio从Java 7更新到Java 8,出现了这个问题。然后我是这样解决的:

android {
    defaultConfig {
    }
    buildTypes {
    }
    packagingOptions{
        exclude 'META-INF/rxjava.properties'
    }
}

在我的例子中,只排除你的项目/app/build上的“META-INF/DEPENDENCIES”路径就足够了。Gradle在android{}内。在这里

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
}

然后做清洁项目和重建项目。