为什么会出现此错误"在打包APK期间复制文件"?如何解决此错误?

时间:2015-07-01 05:29:27

标签: android android-gradle android-library

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

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

2 个答案:

答案 0 :(得分: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'
    }

答案 1 :(得分:0)

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

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