首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >找到多个具有独立于操作系统的路径'META-INF/LICENSE‘的文件

找到多个具有独立于操作系统的路径'META-INF/LICENSE‘的文件
EN

Stack Overflow用户
提问于 2017-06-03 17:31:08
回答 30查看 384.4K关注 0票数 490

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

错误:任务':app:transformResourcesWithMergeJavaResForDebug'.执行失败找到多个具有独立于操作系统的路径'META-INF/LICENSE‘的文件

这是我的build.gradle文件:

代码语言:javascript
复制
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文件中时,

代码语言:javascript
复制
  packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }

这个错误会得到解决,但会出现另一个问题。如下所示:

代码语言:javascript
复制
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)

谁有办法解决这个问题呢?

EN

回答 30

Stack Overflow用户

发布于 2017-11-27 19:06:04

您可以在android{}内部的yourProject/app/build.gradle中添加此代码。exclude函数将命名的资源添加到未打包在APK中的资源列表中。

代码语言:javascript
复制
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") 
      }          
}

exclude函数在7.0.2中已弃用,您应该使用类似以下内容的内容:

代码语言:javascript
复制
android {
   ...
   packagingOptions {
       resources.excludes.add("META-INF/*")
   }
}
票数 690
EN

Stack Overflow用户

发布于 2017-06-27 03:47:58

在我的例子中,只需在android{}中排除yourProject/app/build.gradle上的路径'META-INF/DEPENDENCIES‘就足够了。就是这里

代码语言:javascript
复制
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
}

然后执行Clean Project和Rebuild Project。

票数 184
EN

Stack Overflow用户

发布于 2018-01-13 01:20:53

这里的解决方案帮不了我,但this link帮了我。

如果你有一个库正在添加一些android .so文件-like libassmidi.solibgnustl_shared.so-你必须告诉gradle在打包时只选择一个,否则你会得到冲突。

代码语言:javascript
复制
android {
  packagingOptions {
    pickFirst 'lib/armeabi-v7a/libassmidi.so'
    pickFirst 'lib/x86/libassmidi.so'
  }
}

在使用React Native应用程序作为Android项目中的库时,我遇到了这个问题。希望能有所帮助

票数 102
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44342455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档