Android 发现多个文件具有独立于操作系统的路径';META-INF/LICENSE';

Android 发现多个文件具有独立于操作系统的路径';META-INF/LICENSE';,android,gradle,build.gradle,Android,Gradle,Build.gradle,当我构建应用程序时,出现以下错误: 错误:任务“:app:transformResourcesWithMergeJavaResForDebug”的执行失败。 发现多个文件具有独立于操作系统的路径“META-INF/LICENSE” 这是我的build.gradle文件: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 25 buil

当我构建应用程序时,出现以下错误:

错误:任务“:app:transformResourcesWithMergeJavaResForDebug”的执行失败。 发现多个文件具有独立于操作系统的路径“META-INF/LICENSE”

这是我的build.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'
}
当我将此代码添加到build.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)

谁有办法解决这个问题?

在我的例子中,只排除
yourProject/app/build.gradle
inside
android{}
上的路径“META-INF/DEPENDENCIES”就足够了。给你

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
}

然后执行清理项目和重建项目。

您可以在
yourProject/app/build.gradle
inside
android{}

android {      
      packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude("META-INF/*.kotlin_module") 
      }          
}
有类似的信息

错误:任务“:app:transformResourcesWithMergeJavaResForDebug”的执行失败。 发现多个文件具有独立于操作系统的路径“constant values.html”

为了解决这个问题,我必须在AndroidStudio中启用packages视图(1),然后在树中浏览到库,并找到重复项(2

然后,按ctrl+alt+f12(或RMB菜单)(3)并找到导致问题的库。 列出导致问题的libs中的文件列表,并将其写入app的build.gradle文件android部分。另一个选择是处理包含重复文件的库

packagingOptions {
    exclude 'allclasses-frame.html'
    exclude 'allclasses-noframe.html'
    <..>
包装选项{
排除“allclasses frame.html”
排除'allclasses noframe.html'

我遇到了类似的问题。我收到了错误消息-

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

More than one file was found with OS independent path 'javax/annotation/WillCloseWhenClosed.java'
正如上面的一些答案所述,使用下面的代码是有效的

'packagingOptions {
       exclude 'allclasses-frame.html'
    }'
但是我在20个不同的文件中遇到了这个错误,所以在排除了20个文件之后,我停下来尝试找到一个合适的解决方案

'Unable to execute dex: Multiple dex files' error.
我终于解决了这个问题

首先(在我的例子中,WillCloseWhenClosed.java是重复文件),在android studio中,您可以选择“到处搜索”。在那里写入并搜索该文件。在那里我找到了该文件的多个实例。因此,我单击了这两个实例,并通过右键单击该文件并查看其在android studio中打开时的位置来查看其位置

其次,我发现gradle文件中有一些依赖项

dependencies {
    compile 'com.google.api-client:google-api-client:1.23.0'
}
我在以下位置也有相同的zip包:\Users\user\AndroidStudioProjects\git\appname\app\libs\google-http-client-1.23

所以这是多余的,这就是为什么gradle找到了2个文件。所以我删除了我的zip包,它为我解决了错误。执行此操作时要小心。你必须找出要删除的正确文件或包

第三,gradle还在这个位置制作了这些bug文件的压缩包(至少对我来说是这样)-C:\ProgramFiles\Android\Android Studio\gradle\m2repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar

所以我也从这里删除了jsr305-1.3.9.jar文件


如果您仍然感到困惑,只需在android studio中的“搜索所有地方”,在那里找到您的文件实例,您将不得不删除其中一个。慢慢来,找出其中一个。

这里的解决方案对我没有帮助,但确实帮了我

如果你有一个库正在添加一些android.so文件,比如
libassmidi.so
libgnustl\u shared.so
,你必须告诉gradle在打包时只选择一个,否则你会遇到冲突

android {
  packagingOptions {
    pickFirst 'lib/armeabi-v7a/libassmidi.so'
    pickFirst 'lib/x86/libassmidi.so'
  }
}

在Android项目中将React原生应用程序用作库时,我遇到了这个问题。希望它能有所帮助。

基本上,当gradle将apk文件放在一起时,它会复制所有编译依赖项的内容,它足够智能,可以看到有一个重复的文件..来自两个不同的jar文件。这可以是像.tx这样的任何文件t或META-INF/DEPENDENCIES。最好使用以下选项排除这些文件,以防该文件仅用于提供信息

android{
    packagingOptions {
       exclude 'META-INF/DEPENDENCIES'
    }
}

或者,如果在这种情况下,该文件是一个强制性文件,如类文件,在两个相互关联的jar依赖项之间进行了复制,那么最好以更兼容的版本找到这些jar的替代品。

我将Studio从Java 7更新为Java 8,出现了这个问题。然后我用以下方式解决了这个问题:

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

我遇到了这个问题,首先是一些本机库(.so文件)然后是java/kotlin文件。结果表明,我包括了一个源代码库以及通过可传递依赖项引用artifactory。检查依赖项树以查看是否有任何冗余项。使用
/gradlew:app:dependencies
获取依赖项树。替换“app”如果主模块名称不同,请使用您的模块名称。

我遇到了相同的问题,我尝试了此方法

错误: 发现多个文件具有独立于操作系统的路径“META-INF/library\u release.kotlin\u module”

解决方案:

android {
    packagingOptions {
    exclude 'META-INF/library_release.kotlin_module'
    }
}

我在我的应用程序中添加了jar依赖项,如下所示:

implementation files('libs/json-simple-1.1.1.jar')
implementation group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26'
但我意识到,由于依赖项中的第一行,它们已经被添加:

implementation fileTree(include: ['*.jar'], dir: 'libs')
此行将lib文件夹中的所有jar添加到应用程序依赖项中

因此,在删除额外的依赖项
实现文件('libs/json-simple-1.1.1.jar')


它工作正常。

我遇到了相同的错误,我发现这是由于不同的模块包含来自不同包的相同类造成的

e、 g.一个使用androidx包装,另一个使用androidx之前的包装

我通过使用Android Studio的内置功能将androidx之前的模块迁移到androidx解决了这个问题:“重构-->迁移到androidx…”,不排除任何内容


根据你的情况,你可以检查一下你是否有家属
configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
  packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
android{
    ...
    ...
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }

}
packagingOptions {
    exclude 'META-INF/LICENSE.md'
    exclude 'META-INF/NOTICE.md'
}
implementation 'androidx.annotation:annotation:1.1.0'
android.useAndroidX=true
 More than one file was found with OS independent path 'androidsupportmultidexversion.txt'
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
    exclude("META-INF/*.kotlin_module") 
} 

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

    }
}
android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/INDEX.LIST'
    }
}
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
   
}

dependencies {
    def multidex_version = "2.0.1"
    implementation 'androidx.multidex:multidex:$multidex_version'
}
dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
<application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
</application>
<application
            android:name=".G" >
        ...
</application>
implementation 'org.junit.jupiter:junit-jupiter:5.6.2'
implementation group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26'
packagingOptions {
    exclude 'META-INF/lib_release.kotlin_module'
}