为什么此错误"Duplicate files during packaging of APK"发生?如何修复此错误?



我在运行应用程序时发现了这个错误,并尝试了一些解决方案。但这并不能解决我的问题。

我已经将这些行添加到我的build.gradle文件中

 packagingOptions {
    exclude  'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENCE'
}

但仍然存在同样的错误。错误日志

Error:duplicate files during packaging of APK I:CameraPhotoVideoUploadappbuildoutputsapkapp-debug-unaligned.apk
Path in archive: META-INF/LICENSE
Origin 1: I:CameraPhotoVideoUploadapplibshttpmime-4.3.6.jar
Origin 2: I:CameraPhotoVideoUploadapplibshttpclient-4.3.6.jar
You can ignore those files in your build.gradle:
android {
  packagingOptions {
    exclude 'META-INF/LICENSE'
  }
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE
File 1: I:CameraPhotoVideoUploadapplibshttpmime-4.3.6.jar
File 2: I:CameraPhotoVideoUploadapplibshttpclient-4.3.6.jar
Information:BUILD FAILED

我不明白这个问题。有人能帮忙吗??

渐变文件

apply plugin: 'com.android.application'
android {
packagingOptions {
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENCE'
}
compileSdkVersion 21
buildToolsVersion "23.0.0 rc2"
defaultConfig {
    applicationId "info.androidhive.camerafileupload"
    minSdkVersion 11
    targetSdkVersion 21
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
    compile files('libs/httpclient-4.3.6.jar')
    compile files('libs/httpcore-4.3.3.jar')
    compile files('libs/httpmime-4.3.6.jar')
}
}

用这个替换你的等级

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "your_package_name"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
   packagingOptions {
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/DEPENDENCIES'
      exclude 'META-INF/LICENCE'
      }
     }
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    <!--Jar's Goes Here-->
}

仍然收到错误意味着更换包装选项

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

字符串比较区分大小写,请尝试

  packagingOptions {
    exclude  'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/licence' //write licence in lowercase
}

相关内容

  • 没有找到相关文章

最新更新