2016-12-06 33 views
0

我试图在this教程中将Google+注册/登录集成到Android Studio中导入的旧版(Eclipse)项目中。在导入build.gradle文件时,我被卡住了。在实现Google +登录时在build.gradle中重复输入

错误说:

Error:Execution failed for task ':Study Story:transformClassesWithJarMergingForDebug'. 
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$1.class 

我不能到调试的这种错误的原因。内水平的build.gradle文件有以下代码:

import java.util.regex.Pattern 

apply plugin: 'android' 

apply plugin: 'com.github.triplet.play' 
apply from: 'signingRelease.gradle' 
apply plugin: 'signing' 



android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 
    useLibrary 'org.apache.http.legacy' 
    defaultConfig { 
     minSdkVersion 15//lower than 14 doesn't support multidex 
     targetSdkVersion 21 

     // Enabling multidex support. 
     multiDexEnabled true 

     // For blurring images 
     renderscriptTargetApi 18 
     renderscriptSupportModeEnabled true 
    } 

    buildTypes{ 
     release { 
      signingConfig signingConfigs.publishApkRelease 
     } 
     debug { 
      signingConfig signingConfigs.debug 
     } 


    } 
    play { 
     track = 'beta' 
     serviceAccountEmail = '[email protected]account.com' 
     pk12File = file('keyfile.p12') 
    } 

    configurations { 
     all*.exclude group: 'com.android.support', module: 'support-v4' 
     all*.exclude module: 'support-annotations' 
    } 
    repositories { 
     jcenter() 
    } 

    lintOptions { 
     abortOnError false 
    } 

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



dependencies { 
    compile project(':Viewpage:viewpage-library') 
    compile project(':CountryPicker') 
    compile project(':numberpicker-library') 
    compile('com.facebook.android:facebook-android-sdk:4.13.0') { 
     exclude module: 'bolts-android' 
     exclude module: 'support-v4' 
    } 

    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' 

    compile 'com.parse.bolts:bolts-android:1.+' 
    //compile 'com.parse:parse-android:1.11.0' 
    compile 'com.parse:parse-android:1.+' 
    //compile 'com.google.android.gms:play-services:8.3.0' 
    compile 'com.google.android.gms:play-services-auth:9.0.0' 

    // glide is added to load the g+ profile image. Ignore if you want 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.google.android.gms:play-services-maps:9.0.0' 
    compile 'com.google.android.gms:play-services-analytics:9.0.0' 

    compile 'com.android.support:appcompat-v7:22.2.0' 
    compile 'com.android.support:design:22.+' 
    compile 'com.shamanland:fab:0.0.6' 

    //compile 'com.parse.bolts:bolts-android:1.1.+' 


    //compile fileTree(include: 'Parse-*.jar', dir: 'libs') 
    // compile fileTree(include: ['ParseFacebookUtilsV4-1.9.2.jar'], dir: 'libs') 
    compile fileTree(include: ['jsoup-1.7.3.jar'], dir: 'libs') 

    compile fileTree(include: ['ParseFacebookUtilsV4-1.10.3.jar'], dir: 'libs') 


    // compile fileTree(include: ['libGoogleAnalyticsServices.jar'], dir: 'libs') 
    //compile fileTree(dir: 'libs', include: ['android-support-multidex.jar']) 
    compile 'com.android.support:multidex:1.0.1' 

    compile 'com.android.support:recyclerview-v7:22.2.1' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.github.traex.rippleeffect:library:1.3' 
    //SwipyRefreshLayout 
    compile 'com.github.orangegangsters:swipy:[email protected]' 

    // compile 'com.facebook.android:facebook-android-sdk:4.1.0' 

    compile('com.android.support:cardview-v7:23.2.0') { 
     force = true 
    } 

} 

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

/* 

This is not working yet. 

*/ 

task('increaseVersionCode') << { 
    println('in increaseVersionCode') 
    def manifestFile = file("AndroidManifest.xml") 
    def pattern = Pattern.compile("versionCode=\"(\\d+)\"") 
    def manifestText = manifestFile.getText() 
    def matcher = pattern.matcher(manifestText) 
    matcher.find() 
    def versionCode = Integer.parseInt(matcher.group(1)) 
    println('in increaseVersionCode ' + versionCode) 
    def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"") 
    manifestFile.write(manifestContent) 
} 

task('incrementVersionName') << { 
    println('in incrementVeriosnName') 
    def manifestFile = file("AndroidManifest.xml") 
    def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\\.(\\d+)\"") 
    def manifestText = manifestFile.getText() 
    def matcherVersionNumber = patternVersionNumber.matcher(manifestText) 
    matcherVersionNumber.find() 
    def majorVersion = Integer.parseInt(matcherVersionNumber.group(1)) 
    def minorVersion = Integer.parseInt(matcherVersionNumber.group(2)) 
    def buildVersion = Integer.parseInt(matcherVersionNumber.group(3)) 
    def mNextVersionName = majorVersion + "." + minorVersion + "." + (buildVersion + 1) 
    println('Major Version ' + majorVersion) 
    println('Minor Version ' + minorVersion) 
    println('Build Version ' + buildVersion) 
    def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"") 
    manifestFile.write(manifestContent) 
} 

//Activate this if you wish for Gradle to handle the build number increments. 
/* 
tasks.whenTaskAdded { task -> 
    println('When task is added: ' + task.name) 
    if (task.name == 'generateDebugBuildConfig') { 
     // println('IN IFSTATMENTWITH : ' + task.name) 
     task.dependsOn 'increaseVersionCode' 
     task.dependsOn 'incrementVersionName' 
    } 
}*/ 

项目级别(外)的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:1.2.3' 
     classpath 'com.android.tools.build:gradle:1.3.0' 
     classpath 'com.github.triplet.gradle:play-publisher:1.1.4' 
     classpath 'com.android.tools.build:gradle:2.1.0' 
     classpath 'com.google.gms:google-services:3.0.0' 
     //classpath 'com.google.gms:google-services:1.4.0-beta3' 
    } 

    System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true' 

} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

的文件夹结构看起来像下面图像:

enter image description here

请指出我需要修改以解决问题的区域。

+0

检查此http://计算器。 com/questions/35156072/android-errorexecution-failed-for-task-transformclasseswithjarmergingfordeb – Shailesh

+0

这对我不起作用,我已经尝试过了。 – kittu88

回答

0

首先,尽量使用相同的API为compileSdkVersionbuildToolsVersiontargetSdkVersionsupport:appcompat依赖,support:design依赖,support-recyclerview依赖,依赖support:cardview。在您的应用程序build.gradle中,您需要坚持到API 23

据我所知,如果你使用:(如果我的记忆为我好)

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' 

,因为它做同样与useLibrary

useLibrary 'org.apache.http.legacy' 

你不需要添加这种依赖关系。

然后在你的根的build.gradle,你只需要一个构建工具的gradle:

//classpath 'com.android.tools.build:gradle:1.3.0' Use only one. 
classpath 'com.android.tools.build:gradle:2.1.0' 

而在去年,尽量不要使用multidex为您的应用程序。因为没有multidex,Android应用程序更快。 Imho,通过浏览你的build.gradle,你可以不用multidex。

0

首先确保您的Android SDK已更新,并使用您指定为您的项目依赖项的相同版本的库。现在回答这个错误:

这些导入:所以你需要如下排除它们

Error:Execution failed for task ':Study Story:transformClassesWithJarMergingForDebug'. 
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$1.class 

com.android.support:support-v4和支持的注解包导入不同版本多次support-v4,support-annotations 23.0.0:

compile('com.google.android.gms:play-services-auth:9.0.0') { 
     exclude module: 'support-v4' 
     exclude module: 'support-annotations' 
    } 

compile('com.google.android.gms:play-services-maps:9.0.0') { 
      exclude module: 'support-v4'  
      exclude module: 'support-annotations' 
     } 

compile('com.google.android.gms:play-services-analytics:9.0.0') { 
       exclude module: 'support-v4' 
       exclude module: 'support-annotations'   
      } 

这是导入support-v4,support-annotations 22.0.0。

// Just don't import this library as it's already imported in 'com.android.support:design' 
    compile('com.android.support:appcompat-v7:22.2.0') { 
         exclude module: 'support-v4' 
         exclude module: 'support-annotations' 
        } 

这是导入support-v4 25.0.1。你永远不应该指定具有依赖关系的依赖项:'com.android.support:design:22.+',因为它总是会强制项目使用最新的库,同时构建可能导致几个构建错误的gradle,一些不推荐使用的类你的项目不稳定。总是建议及时更新SDK并相应地指定相关版本,并验证写入的代码是否是您的项目不会丢失最新库中的任何类。实际上,设计库正在导入support-v4,appcompat-v7,support-annotations,recyclerview-v7,因此您应该避免单独导入这些库。

compile 'com.android.support:design:25.0.1' 

它再次导入support-v4,support-annotations 22.2.1。

// Just don't import this library as it's already imported in 'com.android.support:design' 
    compile('com.android.support:recyclerview-v7:22.2.1') { 
           exclude module: 'support-v4' 
           exclude module: 'support-annotations'   
          } 

这个库下面导入模块具有23.1.1版本:

compile('com.github.orangegangsters:swipy:[email protected]') { 
            exclude module: 'support-v4' 
            exclude module: 'appcompat-v7' 
            exclude module: 'support-annotations'   
           } 

它导入支持的注解:22.0.0

compile('com.github.traex.rippleeffect:library:1.3') { 
             exclude module: 'support-annotations'   
            }