任务':transformClassesWithJarMergingForDebug'的Android项目错误执行失败

Posted

技术标签:

【中文标题】任务\':transformClassesWithJarMergingForDebug\'的Android项目错误执行失败【英文标题】:Android Project Error Execution failed for task ':transformClassesWithJarMergingForDebug'任务':transformClassesWithJarMergingForDebug'的Android项目错误执行失败 【发布时间】:2016-10-26 14:25:27 【问题描述】:

我正在将我的 android 应用程序从 eclipse 转换为 Android Studio。当我构建 gradle 时没有错误。但是在运行应用程序时,我遇到了以下错误:

Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/xmlpull/v1/XmlPullParserException.class

我多次尝试清理/重建项目,但总是遇到同样的错误。 我也试过终端命令 ./gradlew 来清理它,但它不起作用。

Android Studio 版本:2.1 摇篮版本:2.1.2 jdk 版本:1.8 Android SDK 构建工具:24 个

build.gradle 代码:

    apply plugin: 'com.android.application'

dependencies 

    compile ('com.google.android.gms:play-services:9.0.2')
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile files('libs/appcompat_v7.jar')
    compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
    compile files('libs/gcm.jar')
    compile files('libs/android.jar')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')

    compile ('com.google.android.gms:play-services-analytics:9.0.2')
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/mail.jar')
    compile "com.android.support:support-v4:24.0.0"
    compile "com.android.support:design:24.0.0"
    compile 'com.android.support:multidex:1.0.1'


buildscript 
    repositories 
        jcenter()
    
    dependencies 
        classpath 'com.android.tools.build:gradle:2.1.2'
    


android 
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary  'org.apache.http.legacy'

    defaultConfig 

        applicationId "com.expedite.apps.vedant"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    


    sourceSets 
        main 
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        

        // 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')
    

【问题讨论】:

Add this... in your project build... packagingOptions exclude 'META-INF/NOTICE.txt' // 不会包含 NOTICE 文件 exclude 'META-INF/LICENSE.txt' / / 不会包含许可证文件 感谢您回答我的问题。现在我被添加到 build.gradle 但错误没有解决。索尔请给我其他解决方案。 出现同样的错误??用我的回答 是的。错误:任务“:transformClassesWithJarMergingForDebug”执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:org/xmlpull/v1/XmlPullParserException.class 【参考方案1】:

我解决了我的错误:

按照我的 build.gradle 代码:

    apply plugin: 'com.android.application'

dependencies 
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile('com.google.android.gms:play-services:9.0.2')
    compile ('com.google.android.gms:play-services-analytics:9.0.2')
    compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
    compile "com.android.support:design:24.0.0"
    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/mail.jar')
    compile files('libs/activation.jar')
    compile files('libs/gcm.jar')


buildscript 
    repositories 
        jcenter()
    
    dependencies 
        classpath 'com.android.tools.build:gradle:2.1.2'
    


android 
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary  'org.apache.http.legacy'

    defaultConfig 

        applicationId "com.expedite.apps.vedant"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    
    packagingOptions 
        exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
        exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
        exclude 'META-INF/LICENSE-FIREBASE.txt'
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    
    dexOptions 
        javaMaxHeapSize "4g"
    

    sourceSets 
        main 
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        

        // 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')
    

在AndroidManifest.xml中添加这一行 android:name="android.support.multidex.MultiDexApplication"

<application
 .....
 android:name="android.support.multidex.MultiDexApplication">
</application>

【讨论】:

【参考方案2】:

在您的构建中添加一些代码

我正在添加一些行,例如 Package Option 和 Build Types...

apply plugin: 'com.android.application'

dependencies 


compile 'com.android.support:appcompat-v7:24.0.0'
compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')

compile 'com.google.android.gms:play-services:+'
compile files('libs/libGoogleAnalyticsServices.jar')

compile "com.android.support:support-v4:24.0.0"
compile "com.android.support:design:24.0.0"
compile 'com.android.support:multidex:1.0.1'



buildscript 
repositories 
    jcenter()

dependencies 
    classpath 'com.android.tools.build:gradle:2.1.2'



android 
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary  'org.apache.http.legacy'



defaultConfig 

    applicationId "com.expedite.apps.vedant"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true



 packagingOptions 
    exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file

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

sourceSets 
    main 
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    

    // 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')


【讨论】:

感谢您回答我的问题。现在我被添加到 build.gradle 但错误没有解决。索尔请给我其他解决方案。 尝试清理项目并再次重建。放置此代码后 并且还尝试添加 compile('com.google.android.gms:play-services:8.1.0') exclude group: 'com.android.support', module: 'support -v4' 而不是编译 ('com.google.android.gms:play-services:9.0.2') 是的,我尝试清理项目并重建,但出现同样的错误。错误:错误:任务“:transformClassesWithJarMergingForDebug”执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:org/xmlpull/v1/XmlPullParserException.class 否则你也用 compile 'com.google.android.gms:play-services:+' 编译

以上是关于任务':transformClassesWithJarMergingForDebug'的Android项目错误执行失败的主要内容,如果未能解决你的问题,请参考以下文章

任务计划程序打开软件的原理

CELERY 定时任务

“异步任务然后等待任务”与“任务然后返回任务”[重复]

宏任务和微任务的执行顺序

宏任务和微任务

20230515学习笔记——js中的同步任务与异步任务,宏任务与微任务