More than one file was found with OS independent path 'META-INF/LICENSE'

匿名 (未验证) 提交于 2019-12-03 01:27:01

问题:

When i build my app, I got follow error .

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path 'META-INF/LICENSE'

This is My build.gradle file

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' } 

when I add those code to my gradle file.

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

This error would be solved , but another problem will happen. like this

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) 

Who has ideas for this question ? Thanks for first.

回答1:

I my case it was enough to exclude only path 'META-INF/LICENSE' on yourProject/app/build.gradle inside android{} . Here it is

packagingOptions {     exclude 'META-INF/LICENSE' } 

And then do Clean Project and Rebuild Project.



回答2:

You can add this in yourProject/app/build.gradle inside 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' } 


回答3:

Had similar message

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

To resolve it, I had to enable packages view(1) in Android Studio, then browse through the tree to libraries, and locate the duplicates(2)

Then, ctrl+alt+f12 (or RMB menu)(3) - and found libraries which caused the issue. Made list of files inside those libs which caused the issues, and wrote them to app's build.gradle file inside android section. Other option is to deal with the library, containing duplicate files

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



回答4:

The solutions here didn't help me, but this link did: https://groups.google.com/forum/#!topic/Android-ndk/vfMfld5FY7A

libassmidi.so or libgnustl_shared.so

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

I was having this issue when using a React Native app as a library in an Android project. Hope it helps



回答5:

I had a similar problem. i was getting the error message -

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.  More than one file was found with OS independent path 'javax/annotation/WillCloseWhenClosed.java' 

As stated in some of the answers above, using the below code works

'packagingOptions {        exclude 'allclasses-frame.html'     }' 

But i was getting this error for 20 different files, so after excluding 20 files, i stopped and tried to find a decent solution. I had also encountered the

'Unable to execute dex: Multiple dex files' error. 

I finally managed to solve this.

Firstly (as in my case WillCloseWhenClosed.java was the duplicate file), in android studio you have an option of 'search everywhere'. Write and search for the file there. There i found multiple instances of this file. So i clicked on both instances and saw their location by right clicking on the file and seeing its location when they opened in android studio.

Secondly, I figured out that i had some dependencies in gradle file. I was using the below code

dependencies {     compile 'com.google.api-client:google-api-client:1.23.0' } 

and also i had their same zip packages in the location :\Users\user\AndroidStudioProjects\git\appname\app\libs\google-http-client-1.23!.

So this was redundant and thats why gradle is finding 2 files. So i deleted my zip packages and it solved the errors for me. Be carefull while doing this. You have to figure out which is the correct file or package to be deleted.

Thirdly, gradle also makes a zip of these bug files in this location (At least for me it made) - C:\Program Files\Android\Android Studio\gradle\m2repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar!

so i went and deleted the jsr305-1.3.9.jar file from here also.

If you are still confused, just go the 'search everywhere' in android studio, find instances of your file there and you would have to delete one of them. Take your time and figure out which one.



回答6:

Basically when gradle puts together the apk file, it copies content from all the compile dependencies, It is intelligent enough to see that there is a duplicate file..coming from two different jar files. This could be any file like a.txt or META-INF/DEPENDENCIES. It might be best to exclude these files using the below, in case the file is present there only for informational purposes.

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

Or if in case, the file is a mandatory file like a class file, that has been duplicated across two jar dependencies that are related to each other, it is best to find alternatives to these jars, in the way of a more compatible version.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!