2

First of all I want to admit that I know most of questions about gradle problems. It's not a duplicate. Problem is similar to others but all solutions failed. Problem has happened when I've added google play services ads lib. Before it app had been building properly. After addition classical problem occurs.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 1
in some cases exit value was 3

I have changed gradle file many times with several module exclusions, enlarging android studio heap size and many other possibilities. After all tries I cannot figure out what is wrong.

Gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.google.gms.google-services'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://clojars.org/repo/" }
    maven { url "https://jitpack.io" }

}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "xxx"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    dexOptions {
        preDexLibraries = false
     //I have also tried enlarging heap size here
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    apt "com.google.dagger:dagger-compiler:2.0.2"
    // Needed for @Generated annotation (missing in Java <= 1.6; therefore, Android)
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    //ads lib ruined building
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile("com.google.android.gms:play-services-gcm:8.3.0") {
        exclude module: 'httpclient' //by artifact name
        exclude group: 'org.apache.httpcomponents' //by group
        exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
    }
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.google.guava:guava:19.0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup.okhttp:okhttp:2.7.4'
    compile('com.squareup.retrofit2:retrofit:2.0.0-beta4') {
        exclude module: 'okhttp'
    }
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.google.dagger:dagger:2.0.2'
    compile('com.google.apis:google-api-services-youtube:v3-rev162-1.21.0') {
        exclude group: 'com.google.guava'
        exclude module: 'httpclient' //by artifact name
        exclude group: 'org.apache.httpcomponents' //by group
        exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
    }
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'com.github.orhanobut:logger:1.12'
    compile 'javax.annotation:jsr250-api:1.0'
    compile 'frankiesardo:icepick:3.1.0'
    apt 'frankiesardo:icepick-processor:3.1.0'
}

I don't want to use whole google play services lib.

Gradle console output when the error occurs:

: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 2 errors; aborting FAILED
BactaTank
  • 164
  • 2
  • 10
  • 1
    "After addition classical problem occurs" -- usually, the real problem is described somewhere earlier in the Gradle console than what you have included in your question. Please edit your question to include the entire Gradle console output for this build, not just these few lines. – CommonsWare Mar 08 '16 at 13:40
  • :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 2 errors; aborting FAILED That's all. Before addition of ads lib everything works properly. – BactaTank Mar 08 '16 at 13:46
  • 1
    http://stackoverflow.com/questions/30045417/android-studio-gradle-could-not-reserve-enough-space-for-object-heap – CommonsWare Mar 08 '16 at 13:54
  • gradle console output file has 710 and 80% of the warnings are notes like: "Maybe this is program method 'android.support.v4.net.TrafficStatsCompatIcs { void tagSocket(java.net.Socket); }'" or " Maybe this is program field 'com.google.common.base.Functions$ConstantFunction { java.lang.Object value; }' " At the end of that: ":app:transformClassesWithDexForRelease UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: GC overhead limit exceeded" Is that possible to have some recursive dependency in lib? – BactaTank Mar 08 '16 at 14:43
  • 1
    You're using a ton of libraries, maybe it has something to do with that? Try removing a few and see if it works. I've heard multidex can cause a lot of problems. – miva2 Mar 08 '16 at 16:08
  • I know that, but there is no unused lib in gradle file. Additional info Application class extends MultidexApplication class, so I thought multidex should not be a problem. Everything works correctly until I added ads module of google play service. – BactaTank Mar 08 '16 at 16:12
  • 1
    Everything works until you add another library and get an OutOfMemoryError... Sounds like you have too many libraries – OneCricketeer Mar 08 '16 at 16:23
  • It was also my first thought, but the second was: "You must be joking". There must be some way to solve it. Lot of apps have more heavyweight libs and somehow deal with them. – BactaTank Mar 08 '16 at 16:33

1 Answers1

0

According to miva2 and cricket_007 comments - they have right. Too many libraries. I removed

compile 'com.squareup.okhttp:okhttp:2.7.4'

from gradle build file and app has built.

Community
  • 1
  • 1
BactaTank
  • 164
  • 2
  • 10