0

I am building an app where I am using Location Fused Provider and Firebase cloud messaging. When I were using just Firebase cloud messaging everything was okay, but when I added Fused Locations and wanted to build app, console gives me this error:

    Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
    Error:1 error; aborting
    :presentation:transformClassesWithDexForDebug FAILED
    Error:Execution failed for task ':presentation:transformClassesWithDexForDebug'.
 com.android.build.api.transform.TransformException: `com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1`

This is my gradle:

 android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    compileOptions.incremental = false

    defaultConfig {
        applicationId "com.telnet.asp"

        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        multiDexEnabled true

    }

    dataBinding {
        enabled = true
    }

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    apt 'com.google.dagger:dagger-compiler:2.2'
    provided 'javax.annotation:jsr250-api:1.0'

    compile project(path: ':domain')
    compile project(path: ':data')

    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0-rc2'
    compile 'com.android.support:design:23.4.0'
    compile 'javax.inject:javax.inject:1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'com.google.dagger:dagger:2.2'
    compile 'com.android.support:support-v4:23.4.0'

    compile 'com.jakewharton:butterknife:6.1.0'

    compile 'net.danlew:android.joda:2.9.4.1'

    compile 'com.android.support:percent:23.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.firebase:firebase-messaging:9.0.0'
    compile 'com.google.android.gms:play-services:9.0.0'


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

Does anyone know how to fix this? Please help.

3 Answers3

1

Try add

dexOptions {
        javaMaxHeapSize "4g"
    }
Divers
  • 9,531
  • 7
  • 45
  • 88
0

You need to add dexOptions to your build.gradle:

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

    // ...

    dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }
}
eldivino87
  • 1,425
  • 1
  • 17
  • 30
0

Your application is trying to allocate a larger amount of memory and is going OutOfMemory because it fails to.

Make sure to increase the javaMaxHeapSize with

android {
    //...
    dexOptions {
        incremental = true;
        javaMaxHeapSize "4g" // tweak the value here if you need/want
    }
    // ...
}

Also, check this google link regarding this error by checking their stack trace

Ricardo Vieira
  • 1,738
  • 1
  • 18
  • 26
  • And when I put this condition in gradle, does it mean that my problem is solved forever in this app or it is just temporary and I should do something to reduce memory? –  Jul 29 '16 at 09:24
  • Lets see the problem as whole. In the context of this thread you are talking about gradle memory, which refers to the compile-time memory. In this case, you just need to increase the compilation heap and will most likely solve your compilation problems. If you are referring to application memory (heap), yes. You should always handle your memory usage to prevent memory leaks or OutOfMemory errors. Check this post http://stackoverflow.com/questions/38592211/memory-not-freeing-after-fragment-is-removed/38595895#38595895 – Ricardo Vieira Jul 29 '16 at 09:32