2017-06-03 30 views
37

当我构建我的应用程序时,出现跟随错误。发现多个文件与操作系统无关路径'META-INF/LICENSE'

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path '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:[email protected]' 
// 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) 

谁对这个问题有想法?首先感谢。

回答

40

我的情况下,它只是排除内的yourProject/app/build.gradle路径'META-INF/LICENSE'。这里是

packagingOptions { 
    exclude 'META-INF/LICENSE' 
} 

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

+7

这对我来说根本不起作用... –

+6

尝试排除'META-INF/DEPENDENCIES',而不是排除'META-INF/LICENSE' – Pelanes

+0

@ Shore-T试试我的解决方案,我希望它对您有好处 –

35

可以在yourProject/app/build.gradle添加这里面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' 
} 
+1

你节省了我的时间Tnx,为你+1票。 –

+0

@SagarAghara你大部分都很受欢迎^ _ ^我们在这里帮助其他人 –

+1

如果你的回答指定了这个设置的位置,你会很高兴在android {} – tyolab

4

也有类似的消息

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path 'constant-values.html'

要解决这个问题,我不得不启用Android Studio中的包视图(),然后浏览通过树到库,并找到重复项()

然后,按Ctrl + Alt + F12(或RMB菜单)() - 并找到导致问题的库。 在造成问题的那些库文件中创建文件列表,并将它们写入应用程序的build.gradle文件android部分。另一种选择是处理库,包含重复的文件

packagingOptions { 
    exclude 'allclasses-frame.html' 
    exclude 'allclasses-noframe.html' 
    <..> 

enter image description here

0

我也有类似的问题。我居然也得到了错误的信息 -

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包中的位置:\用户\用户\ AndroidStudioProjects \ git的\应用程序名称\程序\库\谷歌HTTP客户端1.23!

所以这是多余的,这就是为什么gradle这个是找到2个文件。所以我删除了我的zip包,它解决了我的错误。在做这件事时要小心。你必须弄清楚哪一个是正确的文件或包要删除。第三,gradle也会在这个位置上生成这些bug文件的zip文件(至少对我来说) - C:\ Program Files \ 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中,找到你的文件的情况下存在,你就必须删除其中之一。慢慢来,弄清楚哪一个。

4

的解决方案,在这里并没有帮助我,但这个环节做的:https://groups.google.com/forum/#!topic/Android-ndk/vfMfld5FY7A

如果有那就是把一些Android的.so文件般libassmidi.solibgnustl_shared.so库 - 你必须告诉gradle这个只选择一个当包装时,否则你会得到冲突。

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

我在使用React Native应用程序作为Android项目中的库时遇到此问题。希望它可以帮助

+0

谢谢,我只有一个.so文件有同样的问题。在同一个文件夹中有另一个名为gdbserver的文件,并且在为它现在工作的库添加packagingOptions之后。 –

1

基本上当gradle这个拼apk文件,从所有的编译依赖它复制的内容,这是非常聪明地看到,有来自两个不同的jar文件复制file..coming。这可以是任何文件,如a.txt或META-INF/DEPENDENCIES。使用下面的内容排除这些文件可能是最好的,以防文件仅用于提供信息。

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

或者,如果在情况下,文件就像一个类文件,已经跨涉及到两个彼此依赖的JAR复制一个强制性的文件,最好是找到替代这些罐子,在更兼容版本的方式。