为什么会发生此错误 "Duplicate files during packaging of APK"?如何解决此错误?

Why this error happen "Duplicate files during packaging of APK"?How to fix this error?

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

我已将这些行添加到我的 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')
}
}

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

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

Replace your gradle with this

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

Still getting the error means replace packagingOptions

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