Java 错误:打包APK Android Studio时出现重复文件错误

Java 错误:打包APK Android Studio时出现重复文件错误,java,android,android-studio,Java,Android,Android Studio,运行应用程序时,我在Android studio中遇到意外错误,下面是我收到的错误消息 错误:APK打包期间文件重复 /home/jithu/libs/android/android/aa/app/build/outputs/apk/app-debug-unaligned.apk 存档中的路径:META-INF/依赖项源1: /home/jithu/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.

运行应用程序时,我在Android studio中遇到意外错误,下面是我收到的错误消息

错误:APK打包期间文件重复 /home/jithu/libs/android/android/aa/app/build/outputs/apk/app-debug-unaligned.apk 存档中的路径:META-INF/依赖项源1: /home/jithu/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.6/cf8bacbf0d476c7f2221f861269365b66447f7ec/httpmime-4.3.6.jar 来源2: /home/jithu/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.1/f5aa318bda4c6c8d688c9d00b90681dcd82ce636/httpcore-4.4.1.jar

我也在粘贴build.gradle文件

 apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


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

你错过了构建渐变的流程。 当您试图使用2
android{..}
snippet时,它没有检测到第二个。因此,排除重复的元文件不起作用

可能的解决方案:

只需更改构建渐变的顺序,如下所示:

    apply plugin: 'com.android.library'    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }
    }
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "org.apache.httpcomponents:httpcore:4.4.1"
    compile "org.apache.httpcomponents:httpmime:4.3.6"


}
如果仍然不起作用,请检查以下内容:

这是你的图书馆吗?
我从主要项目build gradle中排除了重复的元文件。因此,请确保从应用程序模块的构建梯度中排除元文件,而不是库模块。

删除
编译“org.apache.httpcomponents:httpmime:4.3.6”
并尝试..我做到了,但那个时候它允许我编译,但给出了以下错误java.lang.NoClassDefFoundError:org.apache.http.entity.ContentType 05-20 18:44:58.485:E/AndroidRuntime(395):在org.apache.http.entity.mime.content.FileBody。(FileBody.java:89)可能重复:@hareshchelana您可以看到我已经添加了排除语句。仍然是它给了我错误,并且我使用的是studio的最新版本。@MD如果我删除httpime,我们将得到以下类miss errors import org.apache.http.entity.mime.HttpMultipartMode;导入org.apache.http.entity.mime.MultipartEntityBuilder;导入org.apache.http.entity.mime.content.FileBody;这些都丢失了您是否将项目构建梯度中的“PackageOptions{..}”部分从库构建梯度中移动。您是否注意到,您的项目中有多个生成渐变文件。现在可以了,我将“从库中排除”更改为“应用程序”,但我有一个问题,排除这些文件是否会在运行时产生任何问题或影响任何功能?否!元文件不会影响应用程序的任何编程功能。元文件基本上包含开放源代码库的文本信息,如法律公告、许可证等。排除它不会影响任何事情。在下一篇评论中,我还将分享我们将其排除在外的原因。当我们使用多个第三方开源库时,有时两个或多个项目具有相同的命名文本文件(例如:License.txt或Notice.txt或dependencies.txt)。这会在构建时导致冲突。在那一刻,我们强大的android studio建议我们排除那些相互冲突的元文件。