10

My project was working perfectly with those libraries included:

// Support libraries
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
// Other stuff
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.afollestad:material-dialogs:0.7.8.1'
compile 'com.jpardogo.materialtabstrip:library:1.1.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.code-troopers.betterpickers:library:2.0.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.facebook.fresco:fresco:0.7.0'

now i tried to follow this tutorial: Set up a GCM Client App on Android

I added

  1. Add the dependency to your project's top-level build.gradle:
    classpath 'com.google.gms:google-services:1.4.0-beta3'
  2. Add the plugin to your app-level build.gradle:
    apply plugin: 'com.google.gms.google-services'

Then i added :

compile "com.google.android.gms:play-services:8.1.0"

Now when i try to sync, clean, or rebuild. Gradle shows me it is done successfully.

THE ERROR: When i try to run the app and choose device. I get this error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class

This is the last version of my app-level build.gradle:

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

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    defaultConfig {
        applicationId "com.mbh.gcmTest"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 12
        versionName "1.2.2"

        // Enabling multidex support. trying to fix 
        multiDexEnabled true
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    dexOptions {
        preDexLibraries = false
    }
    productFlavors {
    }
}

//compile fileTree(include: ['*.jar'], dir: 'libs')
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
//releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
dependencies {
    provided 'org.glassfish:javax.annotation:10.0-b28'

    // Support Libraries
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'

    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.afollestad:material-dialogs:0.7.8.1'
    compile 'com.jpardogo.materialtabstrip:library:1.1.0'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile 'com.code-troopers.betterpickers:library:2.0.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.facebook.fresco:fresco:0.7.0'

    // FOR GCM
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services:8.1.0'
}

after trying the answer provided by @JBirdVegas I got this error:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1

this is gradle log:

Note: the configuration refers to the unknown method 'void attachBaseContext(android.content.Context)' in class 'com.emse.emseportal3.App'
Note: there were 1 references to unknown class members.
      You should check your configuration for typos.
Note: there were 14 classes trying to access annotations using reflection.
      You should consider keeping the annotation attributes
      (using '-keepattributes *Annotation*').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 20 classes trying to access generic signatures using reflection.
      You should consider keeping the signature attributes
      (using '-keepattributes Signature').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 3 classes trying to access enclosing classes using reflection.
      You should consider keeping the inner classes attributes
      (using '-keepattributes InnerClasses').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 15 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 33 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Note: you're ignoring all warnings!
Preparing output jar [D:\EmseArge\Mohamad\Android\EmsePortal2\app\build\intermediates\multi-dex\debug\componentClasses.jar]
  Copying resources from program jar [D:\EmseArge\Mohamad\Android\EmsePortal2\app\build\intermediates\transforms\CLASSES\FULL_PROJECT\jarMerging\debug\classes.jar]
:app:transformClassesWithDexForDebug
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
3 errors; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
MBH
  • 16,271
  • 19
  • 99
  • 149

1 Answers1

22

Looks like play-services already contains support-v4. Try excluding it from the classpath

compile('com.google.android.gms:play-services:8.1.0') {
    exclude group: 'com.android.support', module: 'support-v4'
}

The second error is different. First thing don't use Java8 it's not supported instead use Java7 Also what version of the Android Gradle Plugin are you using? Try the latest com.android.tools.build:gradle:1.4.0-beta4

Also try not using the latest play-services I ran into an issue compiling against 8.1.0 but not 7.8.0

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • it shows: **cannot resolve symbol module: ';' , '}' or new line expected** – MBH Oct 16 '15 at 07:00
  • after updating the gradle to com.android.tools.build:gradle:1.4.0-beta4, most of warning were fixed, now i got only **jdk1.8.0_51\bin\java.exe** eventhough, i specified java_version_1.7 but still get same error – MBH Oct 16 '15 at 07:37
  • actually now it is another question, you answered my question, i may post another question about java error – MBH Oct 16 '15 at 07:40
  • 2
    @MBH, are you running this through Android Studio? If so you need to update to the latest from the canary channel. The latest plugin causes issues with older Android Studio versions. – JBirdVegas Oct 16 '15 at 15:07
  • when it says about Java version, it is not really the problem, I found out that the problem is exceeding 64K functions when i added google play service , so i added google play service gcm, instead of all google play services, the Java.exe problem was solved ..... – MBH Oct 16 '15 at 15:11
  • 1
    Glad to hear. You also could have implemented `multidex` to get around the limit, but only including what your using is definitely the best method – JBirdVegas Oct 16 '15 at 15:28
  • 1
    anyway thank u alot for saving my day , i would never guess that gradle is not smart enough to exclude support v4 preventing the doublication – MBH Oct 16 '15 at 15:44
  • @JBirdVegas, I am trying to add poi apachi libraries and i am getting this error **Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class** kindly help, i don't understand what is going on i tried the things in your answer already – Pankaj Nimgade Nov 19 '15 at 12:21
  • @PankajNimgade you need to exclude `xmlbeans` from the poi lib – JBirdVegas Nov 20 '15 at 22:44
  • @JBirdVegas, you are right i have done that and after which **gradle** was executing but i could not read any excel file due to missing classes. what should i do. I have run a java project in eclipse using poi libraries. It Ok but i have problem with xmlbeans as it contains many duplicate classes in in – Pankaj Nimgade Nov 21 '15 at 04:35
  • @PankajNimgade you should probably open a new question to explain the problem. – JBirdVegas Nov 21 '15 at 18:22
  • com.android.tools.build:gradle:1.5.0 is not compatible (i dont think) once downgrading this to 1.3.1, my build "works" again. – Nick Mar 21 '16 at 00:07