':app:transformClassesWithJarMergingForDebug'重复输入

时间:2017-03-14 09:22:01

标签: android android-studio android-gradle build.gradle gradle-plugin

我正在从Eclipse导入我的项目,同时构建一个APK,我发现错误。

错误:任务执行失败

  

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / google / android / gms / plus / PlusOneButton $ OnPlusOneClickListener.class

错误:任务执行失败':gruhini:transformClassesWithJarMergingForDebug'。

  

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / google / android / gms / games / Game.class

错误:任务执行失败':gruhini:transformClassesWithJarMergingForDebug'。

  

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / google / android / gms / auth / GoogleAuthException.class

错误:任务执行失败':gruhini:processDebugGoogleServices'。

  

请通过更新google-services插件的版本(https://bintray.com/android/android-tools/com.google.gms.google-services/提供有关最新版本的信息)或将com.google.android.gms的版本更新为9.0.0来修复版本冲突

我的build.gradle:

   apply plugin: 'com.android.application'

   android {
           compileSdkVersion 24
           buildToolsVersion "24.0.3"
           useLibrary 'org.apache.http.legacy'

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

defaultConfig {
    applicationId "com.gruhini"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}



buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
dexOptions {
    incremental true
    preDexLibraries false
    //javaMaxHeapSize "1G" // 2g should be also OK
      }
      }

     dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':eclipseProject')
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/google-play-services.jar')
compile files('libs/httpclient-4.1.jar')
compile files('libs/httpcore-4.1.jar')
compile files('libs/httpmime-4.1.jar')
compile files('libs/itextpdf-5.2.1.jar')
compile files('libs/mail.jar')
compile files('libs/mpandroidchartlibrary-1-7-4.jar')
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'

  }

4 个答案:

答案 0 :(得分:1)

  

com.android.build.api.transform.TransformException:   java.util.zip.ZipException:重复条目:   COM /谷歌/机器人/克/加/

<强>问题

compile files('libs/google-play-services.jar') // Remove this line
compile 'com.google.android.gms:play-services:10.2.0' //10.0.1 or 9.6.0

两者都一样。打电话给其中一个。 然后清理 - 重建并运行

尝试使用应用级别 build.gradle

    apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"

    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "com.gruhini"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 12
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        useLibrary 'org.apache.http.legacy'
        multiDexEnabled true


    }
    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'

    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
        testCompile 'junit:junit:4.12'
        compile project(':eclipseProject')
        compile files('libs/activation.jar')
        compile files('libs/additionnal.jar')
        compile files('libs/httpclient-4.1.jar')
        compile files('libs/httpcore-4.1.jar')
        compile files('libs/httpmime-4.1.jar')
        compile files('libs/itextpdf-5.2.1.jar')
        compile files('libs/mail.jar')
        compile files('libs/mpandroidchartlibrary-1-7-4.jar')
        compile 'com.android.support:support-v4:25.1.0'
        compile 'com.google.android.gms:play-services:10.0.1'
        compile 'com.android.support:appcompat-v7:25.1.0'
        compile 'com.android.support:design:25.1.0'

}

项目级别 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' //2.2.3
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

答案 1 :(得分:0)

在您的gradle文件中安装Android,就像这样。

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

而不是你在dex选项中写。

你的gradle文件看起来像..

apply plugin:'com.android.application'

     android {
               compileSdkVersion 24
               buildToolsVersion "24.0.3"
               useLibrary 'org.apache.http.legacy'
configurations {
                all*.exclude group: 'com.android.support', module:'support-annotations'
        }

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

    defaultConfig {
        applicationId "com.gruhini"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    dexOptions {
        incremental true
        preDexLibraries false
        //javaMaxHeapSize "1G" // 2g should be also OK
          }
          }

         dependencies {
         compile fileTree(dir: 'libs', include: ['*.jar'])
         androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

    })
    compile project(':eclipseProject')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/google-play-services.jar')
    compile files('libs/httpclient-4.1.jar')
    compile files('libs/httpcore-4.1.jar')
    compile files('libs/httpmime-4.1.jar')
    compile files('libs/itextpdf-5.2.1.jar')
    compile files('libs/mail.jar')
    compile files('libs/mpandroidchartlibrary-1-7-4.jar')
    compile 'com.android.support:support-v4:24.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services:10.2.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'

      }

答案 2 :(得分:0)

通过从Gradle中删除以下行来正常工作。编译fileTree(dir:'libs',包括:'* .jar')

答案 3 :(得分:0)

您的软件包中使用的播放服务版本之间不匹配(即使用版本x的软件包,使用版本y的另一个软件包)。

其他答案都没有解释为什么你应该使用播放服务版本x.y.z或如何检查哪一个适用。您可以使用 ./gradlew :app:dependencies

进行检查

您将获得类似于

的输出
|    \--- com.google.android.gms:play-services-tasks:10.2.6 --> (11.0.1)(*)
+--- com.google.android.gms:play-services-basement:11.0.1 (*)

```

在此输出中,您可以看到项目中使用的最新版本的play-services (在上面的示例中,它是11.0.1)。 在 build.gradle 文件中,您应为所有播放服务指定此版本(它们必须是相同的版本)。