【问题标题】:Why this error happen "Duplicate files during packaging of APK"?How to fix this error?为什么会出现“打包 APK 时出现重复文件”的错误?如何解决此错误?
【发布时间】:2015-09-18 03:07:42
【问题描述】:

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

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

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

但仍然有相同的错误。 错误日志

Error:duplicate files during packaging of APK I:\CameraPhotoVideoUpload\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/LICENSE
Origin 1: I:\CameraPhotoVideoUpload\app\libs\httpmime-4.3.6.jar
Origin 2: I:\CameraPhotoVideoUpload\app\libs\httpclient-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:\CameraPhotoVideoUpload\app\libs\httpmime-4.3.6.jar
File 2: I:\CameraPhotoVideoUpload\app\libs\httpclient-4.3.6.jar
Information:BUILD FAILED

我无法理解这个问题。谁能帮忙??

Gradle 文件

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

【问题讨论】:

标签: android android-gradle-plugin android-library


【解决方案1】:

用这个替换你的gradle

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

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

【讨论】:

【解决方案2】:

字符串比较区分大小写,所以试试

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

【讨论】:

  • 如果更改后得到相同的错误日志,则确定名称有问题,试试LICENCE.txt或licence.txt
猜你喜欢
  • 2014-04-23
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 2015-06-21
  • 2021-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多