Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;复制在APK-META-INF/license.txt中的lib文件;Android Studio中的错误_Android_Android Studio - Fatal编程技术网

&引用;复制在APK-META-INF/license.txt中的lib文件;Android Studio中的错误

&引用;复制在APK-META-INF/license.txt中的lib文件;Android Studio中的错误,android,android-studio,Android,Android Studio,我在项目中使用了以下2个库 1.spring-core-3.1.0.RELEASE.jar 2.spring-web-3.1.0.RELEASE.jar 但android studio正在考虑为上述库复制条目,并在打包时给出错误 有人面临类似的问题吗 请建议解决此错误的一些方法。转到您的build.gradle文件并添加以下行: packagingOptions { exclude 'META-INF/license.txt' } 在我的案例中,我必须添加如下内容: apply

我在项目中使用了以下2个库 1.spring-core-3.1.0.RELEASE.jar 2.spring-web-3.1.0.RELEASE.jar

但android studio正在考虑为上述库复制条目,并在打包时给出错误


有人面临类似的问题吗


请建议解决此错误的一些方法。

转到您的
build.gradle
文件并添加以下行:

 packagingOptions {
    exclude 'META-INF/license.txt'
  }
在我的案例中,我必须添加如下内容:

apply plugin: 'com.android.library'    
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    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')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


}
注意:

  • 元文件不会影响应用程序的任何编程功能。元文件基本上包含开放源代码库的文本信息,如法律公告、许可证等。排除它不会影响任何事情

  • 当我们使用多个第三方开源库时,有时两个或多个项目具有相同的命名文本文件(例如:License.txt或Notice.txt或dependencies.txt)。这会在构建时导致冲突。在那一刻,我们强大的android studio建议我们排除那些相互冲突的元文件


  • 我有最简单的txt文件解决方案。如果删除依赖项中的所有txt文件

    仅添加此块

    packagingOptions {
        exclude '**/*.txt'
    }
    
    重要提示:排除文件时,请注意它区分大小写 我将此添加到gradle中,但它不起作用:

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    
    我发现了一个错误:

    Duplicate files copied in APK META-INF/notice.txt
    
    因此,修复方法是添加META-INF/notice.txt:

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

    我必须同时添加
    排除'META-INF/LICENSE.txt'排除'META-INF/NOTICE.txt'
    您也可以
    排除'META-INF/*'
    排除所有文件。@Mohammad Arman关于禁止删除许可文件/通知的许可证怎么办?可能是
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
    }