Prograurd Re-write to zip record

I have a problem signing and releasing an APK. I am getting Duplicate zip warnings and one error. Here is the code:

Information:Gradle tasks [:app:assembleRelease]
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [gcm.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [gson-2.2.4.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [httpmime-4.2.2.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [joda-time-2.1.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [joda-time-2.1.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [joda-time-2.1.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [splunk-mint-4.2.1.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [universal-image-loader-1.9.4.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [support-annotations-24.0.0.jar:META-INF/MANIFEST.MF])
Warning:can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
Error:Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
> java.io.IOException: Can't write [D:\Android\Android_Project\myapp\app\build\intermediates\multi-dex\release\componentClasses.jar] (Can't read [C:\Users\Amir Mahmoud\.android\build-cache\3936c6cf75e73634f829890fcc2030092ab8dabe\output\jars\classes.jar] (Duplicate zip entry [classes.jar:android/support/v4/view/ViewCompat$ICSViewCompatImpl.class]))

      

I even tried adding packaging options to gradle but it didn't work, this is my gradle code:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    useLibrary  'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.company.myapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 70
        versionName "7.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //    compile 'com.android.support:appcompat-v4:25'
    testCompile 'junit:junit:4.12'
    //    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.google.android.gms:play-services:10.2.1'
    //    compile "com.google.android.gms:play-services-gcm:10.2.1"
    //    compile 'org.apache.httpcomponents:httpmime:4.5.3'
    //    compile files('libs/gson-2.2.4.jar')
    //    compile files('libs/httpmime-4.2.2.jar')
    //    compile files('libs/joda-time-2.1.jar')
    //    compile files('libs/universal-image-loader-1.9.4.jar')
//    compile files('libs/android-support-v4.jar')

}

      

I have been stuck with this project for a few days and I have no idea what to do with it, any greetings are appreciated.

+3


source to share


2 answers


In addition to Jareds answer, if you get an error with duplicate files .class

, not just files META-INF/

, you may need to exclude the offending module that contains the duplicate file .class

c).

You will need to determine which dependency includes the module with duplicate entries .class

and exclude that module from the specified dependency.

You can use the Gradle: command ./gradlew app:dependencies

to display the complete dependency graph. Where " app:

" is the name of your project module / application.



After using the command, ./gradlew app:dependencies

you should go through the list of dependencies and find the one that includes the offending module with duplicate entries .class

.

As an example, let's say that com.android.support:support-v4

is a module with duplicate classes causing these errors. Here's how to exclude this duplicate module from your dependency:

//Your dependency that includes the module with the duplicates.
compile('com.my.project:my-module:0.1') {
        //exclude the offending module so there won’t be duplicates.
        exclude module: 'support-v4'
        //maybe you need to exclude a group also?...
        exclude group: 'com.google.android.gms'
    }

      

+4


source


In your Android DSL, just add all the "duplicate zip entries":

android {
    packagingOptions {
        exclude "META-INF/MANIFEST.MF"
        exclude "META-INF/LICENSE.txt"
        exclude "META-INF/NOTICE.txt"
    }
}

      



Docs: https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html

0


source







All Articles