android studio Build funktioniert in debug, schlägt in release-ZipException doppelten Eintrag



android studio gradle tutorial (4)

Danke für die Bearbeitung der Frage. Da es so viele Jar-Bibliotheken gibt, ist es für uns fast unmöglich, den Fehler zu replizieren.

Also, hier ist etwas zu versuchen. Da Sie angegeben haben, dass der Fehler com.android.support:appcompat-v7:25.0.0 , nachdem Sie die com.android.support:appcompat-v7:25.0.0 hinzugefügt com.android.support:appcompat-v7:25.0.0 , gehen Sie folgendermaßen vor:

compile (compile 'com.android.support:appcompat-v7:25.0.0') {
    exclude module: 'support-v4'
}

Sehen Sie, ob es funktioniert oder ob sich der Fehler ändert

BEARBEITEN:

Sie haben den folgenden Befehl ausgeführt: ./gradlew -q dependencies :dependencies --configuration compile

Können Sie diesen Befehl in Ihrem Android Studio-Terminal debugApk und die debugApk und releaseApk Abhängigkeiten in Ihrer Frage veröffentlichen releaseApk

Befehl (ändern Sie die App zu Ihrem Modulnamen, falls dieser anders ist):

./gradlew app:dependencies

Ich aktualisiere eine Anwendung von 2.3 auf Nougat (SDK 25). Wenn ich com.android.support:appcompat-v7:25.0.0 hinzufüge, um ActivityCompat.requestPermissions zu unterstützen. Wenn ich dies im Debug-Modus ausführe, läuft die Anwendung ohne Probleme, aber die Ausführung mit ./gradlew assembleDebug verursacht den folgenden Fehler:

Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/hardware/display/DisplayManagerCompat.class

Wenn ich das im Debug-Modus ausführe, baut die Anwendung ohne Probleme auf. Wenn ich versuche, Build APK zu Build APK , erhalte ich den obigen Fehler.

Gibt es eine Möglichkeit, das doppelte Paket aufzuspüren? Ich habe folgendes ausgeführt:

./gradlew -q dependencies :dependencies --configuration compile

------------------------------------------------------------
Root project
------------------------------------------------------------

compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

(*) - dependencies omitted (listed previously)

Hier ist mein build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

apply plugin: 'com.android.application'

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile fileTree(include: '*.jar', dir: 'libs')
    compile fileTree(include: '*.jar', dir: 'lib')
    compile project(':deps:google-maps-m4b')
    compile project(':deps:android-map-utils:library')
    compile project(':deps:google-play-services')
}

android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'

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

    defaultConfig {
        // Already hit dex limit
        multiDexEnabled true
        dexOptions {
            javaMaxHeapSize "4g"
        }
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Dateien in libs : armeabi/libcryptowrapper.so Dateien in lib :

ClientCertUtil.jar
apache-mime4j-0.6.jar
commons-codec-1.6.jar
commons-io-2.4.jar
commons-logging-1.1.3.jar
gcm.jar
httpclient-4.3.4.jar
httpclientandroidlib-1.2.1.jar
httpcore-4.3.jar
httpmime-4.3.1.jar
javarosa.jar
joda-time-2.0.jar
kxml2-2.3.0.jar
mgrs.jar
opencsv-2.3.jar
regexp-me.jar
zip4j_1.3.2.jar

Beim Hinzufügen des appcompat-v7 exclude module: 'support-v4' zu appcompat-v7 schlägt das Build fehl und das Debug-Protokoll zeigt an, dass die Hauptaktivität nicht mit einem index out of bound, length: 0, index: 3 appcompat-v7 geladen index out of bound, length: 0, index: 3 :

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(net.lingala.zip4j.unzip.Unzip$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.

Laufen

./gradlew -q projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'opendatakit-collect'
\--- Project ':deps'
     +--- Project ':deps:android-map-utils'
     |    \--- Project ':deps:android-map-utils:library'
     +--- Project ':deps:google-maps-m4b'
     \--- Project ':deps:google-play-services'

Running ./gradlew :dependencies da ich scheinbar keinen Projektnamen habe:

Incremental java compilation is an incubating feature.
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

_debugAndroidTestAnnotationProcessor - ## Internal use, do not manually configure ##
No dependencies

_debugAndroidTestApk - ## Internal use, do not manually configure ##
\--- com.android.support:multidex-instrumentation:1.0.1
     \--- com.android.support:multidex:1.0.1

_debugAndroidTestCompile - ## Internal use, do not manually configure ##
\--- com.android.support:multidex-instrumentation:1.0.1
     \--- com.android.support:multidex:1.0.1

_debugAnnotationProcessor - ## Internal use, do not manually configure ##
No dependencies

_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:google-maps-m4b
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:google-maps-m4b
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

_debugUnitTestAnnotationProcessor - ## Internal use, do not manually configure ##
No dependencies

_debugUnitTestApk - ## Internal use, do not manually configure ##
No dependencies

_debugUnitTestCompile - ## Internal use, do not manually configure ##
No dependencies

_releaseAnnotationProcessor - ## Internal use, do not manually configure ##
No dependencies

_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:google-maps-m4b
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:google-maps-m4b
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

_releaseUnitTestAnnotationProcessor - ## Internal use, do not manually configure ##
No dependencies

_releaseUnitTestApk - ## Internal use, do not manually configure ##
No dependencies

_releaseUnitTestCompile - ## Internal use, do not manually configure ##
No dependencies

androidJacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.7.5.201505241946

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.5.201505241946
     +--- org.jacoco:org.jacoco.core:0.7.5.201505241946
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     +--- org.jacoco:org.jacoco.report:0.7.5.201505241946
     |    +--- org.jacoco:org.jacoco.core:0.7.5.201505241946 (*)
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     \--- org.jacoco:org.jacoco.agent:0.7.5.201505241946

androidTestAnnotationProcessor - Classpath for the annotation processor for 'androidTest'.
No dependencies

androidTestApk - Classpath packaged with the compiled 'androidTest' classes.
No dependencies

androidTestCompile - Classpath for compiling the androidTest sources.
No dependencies

androidTestProvided - Classpath for only compiling the androidTest sources.
No dependencies

androidTestWearApp - Link to a wear app to embed for object 'androidTest'.
No dependencies

annotationProcessor - Classpath for the annotation processor for 'main'.
No dependencies

apk - Classpath packaged with the compiled 'main' classes.
No dependencies

archives - Configuration for archive artifacts.
No dependencies

compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:25.0.0
|    +--- com.android.support:support-vector-drawable:25.0.0
|    |    \--- com.android.support:support-compat:25.0.0
|    |         \--- com.android.support:support-annotations:25.0.0
|    \--- com.android.support:animated-vector-drawable:25.0.0
|         \--- com.android.support:support-vector-drawable:25.0.0 (*)
+--- project :deps:google-maps-m4b
+--- project :deps:android-map-utils:library
|    \--- project :deps:google-maps-m4b
\--- project :deps:google-play-services

debugAnnotationProcessor - Classpath for the annotation processor for 'debug'.
No dependencies

debugApk - Classpath packaged with the compiled 'debug' classes.
No dependencies

debugCompile - Classpath for compiling the debug sources.
No dependencies

debugProvided - Classpath for only compiling the debug sources.
No dependencies

debugWearApp - Link to a wear app to embed for object 'debug'.
No dependencies

default - Configuration for default artifacts.
No dependencies

default-mapping - Configuration for default mapping artifacts.
No dependencies

default-metadata - Metadata for the produced APKs.
No dependencies

instrumentTestAnnotationProcessor - Classpath for the annotation processor for 'instrumentTest'.
No dependencies

instrumentTestApk - Classpath packaged with the compiled 'instrumentTest' classes.
No dependencies

instrumentTestCompile - Classpath for compiling the instrumentTest sources.
No dependencies

instrumentTestProvided - Classpath for only compiling the instrumentTest sources.
No dependencies

instrumentTestWearApp - Link to a wear app to embed for object 'instrumentTest'.
No dependencies

provided - Classpath for only compiling the main sources.
No dependencies

releaseAnnotationProcessor - Classpath for the annotation processor for 'release'.
No dependencies

releaseApk - Classpath packaged with the compiled 'release' classes.
No dependencies

releaseCompile - Classpath for compiling the release sources.
No dependencies

releaseProvided - Classpath for only compiling the release sources.
No dependencies

releaseWearApp - Link to a wear app to embed for object 'release'.
No dependencies

testAnnotationProcessor - Classpath for the annotation processor for 'test'.
No dependencies

testApk - Classpath packaged with the compiled 'test' classes.
No dependencies

testCompile - Classpath for compiling the test sources.
No dependencies

testDebugAnnotationProcessor - Classpath for the annotation processor for 'testDebug'.
No dependencies

testDebugApk - Classpath packaged with the compiled 'testDebug' classes.
No dependencies

testDebugCompile - Classpath for compiling the testDebug sources.
No dependencies

testDebugProvided - Classpath for only compiling the testDebug sources.
No dependencies

testDebugWearApp - Link to a wear app to embed for object 'testDebug'.
No dependencies

testProvided - Classpath for only compiling the test sources.
No dependencies

testReleaseAnnotationProcessor - Classpath for the annotation processor for 'testRelease'.
No dependencies

testReleaseApk - Classpath packaged with the compiled 'testRelease' classes.
No dependencies

testReleaseCompile - Classpath for compiling the testRelease sources.
No dependencies

testReleaseProvided - Classpath for only compiling the testRelease sources.
No dependencies

testReleaseWearApp - Link to a wear app to embed for object 'testRelease'.
No dependencies

testWearApp - Link to a wear app to embed for object 'test'.
No dependencies

wearApp - Link to a wear app to embed for object 'main'.
No dependencies

BUILD SUCCESSFUL

Total time: 13.053 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html

Answer #1

Ich bin auch auf dieses Problem gestoßen, als ich das alte Eclipse-Projekt importiert habe. Es ist eine alte Abhängigkeit als JAR-Datei im Projekt aufgetreten.
Erster Weg einfach entfernen

compile fileTree(dir: 'libs', include: '*.jar')

in Gradle-Datei

und fügen Sie Abhängigkeit in der Gradle-Datei hinzu.

Für mich geht das ..

Zweiter Weg Sie haben das wahrscheinlich schon behoben, aber damit das nicht unbeantwortet bleibt, versuchen Sie das zu Ihrem build.gradle:

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

Answer #2

Ich denke, einige der Abhängigkeiten, die Sie hinzugefügt haben, haben appcompat-v4 , was den Fehler verursacht, nicht ganz sicher

Mögliche Lösungen:

  • Versuchen Sie, zip4j_1.3.2.jar entfernen, und fügen Sie erneut compile 'com.android.support:appcompat-v7:24.2.0'

  • der von @ th3pat3l vorgeschlagene: add

compile (compile 'com.android.support:appcompat-v7:25.0.0') { exclude module: 'support-v4' }

Tipp für Api-Versionen> 14:

  • Vermeiden Sie die Verwendung von JARs, weil sie gepackt sind, und Sie können sie kaum ändern. Versuchen Sie stattdessen, sie in der build.gradle-Datei des Projekts zu verwenden, indem Sie eine einfache compile ''xxx.xx.xx

Answer #3

Versuchen Sie, das Projekt zu bereinigen und aus Android Studio neu zu erstellen





android-gradle