错误:在打包APK期间重复文件

时间:2015-07-07 11:49:50

标签: android-studio gradle dependencies duplicates apk

我成功地清理并重建了我的项目但是当我运行它时,它给了我一个错误。我尝试了很多解决方案,但我无法用它们解决。

这是我的错误:

Error:duplicate files during packaging of APK /Users/ege/AndroidStudioProjects/projectandroid/projectAndroid/build/outputs/apk/projectAndroid-debug-unaligned.apk
Path in archive: AndroidManifest.xml
Origin 1: /Users/ege/AndroidStudioProjects/projectandroid/projectAndroid/build/intermediates/resources/resources-debug.ap_
Origin 2: /Users/ege/AndroidStudioProjects/projectandroid/projectAndroid/build/intermediates/javaResources/debug/AndroidManifest.xml
You can ignore those files in your build.gradle:
android {
  packagingOptions {
    exclude 'AndroidManifest.xml'
}
  }
Error:Execution failed for task ':projectAndroid:packageDebug'.
Duplicate files copied in APK AndroidManifest.xml
File 1: /Users/ege/AndroidStudioProjects/projectandroid/projectAndroid/build/intermediates/resources/resources-debug.ap_
File 2: /Users/ege/AndroidStudioProjects/projectandroid/projectAndroid/build/intermediates/javaResources/debug/AndroidManifest.xml

这是我的构建gradle:

apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '23.0.0 rc2'

defaultConfig {
    applicationId "com.project.android"
    minSdkVersion 14
    targetSdkVersion 19

    multiDexEnabled true

}
dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "2g"

}



buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }

    packagingOptions {
        exclude 'AndroidManifest.xml'
    }
}




}

   dependencies {
compile project(':slidingMenuLibrary')
compile project(':pullToRefreshLibrary')
compile project(':placeActivity')
compile project(':jMC')
compile project(':salesforceSDK')
compile project(':library')
compile files('../libMaster/android-integration-2.3-SNAPSHOT.jar')
compile files('../libMaster/com.radaee.pdfex_view.jar')
compile files('../libMaster/core-2.3-SNAPSHOT.jar')
compile files('../libMaster/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')
compile files('../libMaster/libGoogleAnalyticsServices-v3.01.jar')
compile files('../libMaster/urbanairship-lib-3.0.0.jar')
compile 'com.google.api.client:google-api-client-repackaged-com-google-common-base:1.2.3-alpha'
compile 'com.google.code.gson:gson:2.3.1'
compile ('com.android.support:support-v4:22.2.0'){
    exclude group: 'multidex'
}
compile files('../libMaster/commons-lang3-3.1.jar')
compile files('../libMaster/aws-android-sdk-1.4.4-s3.jar')
compile files('../libMaster/aws-android-sdk-1.4.4-core.jar')
compile files('../libMaster/universal-image-loader-1.8.5-with-sources.jar')
}

我也试过这个解决方案,但没有用:

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

3 个答案:

答案 0 :(得分:3)

I currently had the same issue "Duplicate files copied in APK AndroidManifest.xml".

Just do what gradle tell you, putting

android {
  packagingOptions {
      exclude 'AndroidManifest.xml'
}

in build.gradle solved my problem.

答案 1 :(得分:0)

packagingOptions应该在android括号内,而不是像

这样的buildTypes
android {
         packagingOptions {
              exclude 'AndroidManifest.xml'
        }
}

答案 2 :(得分:0)

排除android manifest.xml将有助于构建您的apk,但您的插件都无法在该apk中工作