为什么Gradle会出现此错误?

时间:2016-07-29 07:21:58

标签: android android-gradle fusedlocationproviderapi

我正在构建一个应用程序,我正在使用位置融合提供程序和Firebase云消息传递。当我只使用Firebase云消息时,一切都还可以,但是当我添加Fused Locations并想要构建应用程序时,控制台会给我这个错误:

    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`

这是我的傻瓜:

 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'

有谁知道如何解决这个问题?请帮忙。

3 个答案:

答案 0 :(得分:2)

尝试添加

dexOptions {
        javaMaxHeapSize "4g"
    }

答案 1 :(得分:1)

您需要将build.gradle添加到android { compileSdkVersion 24 buildToolsVersion "23.0.3" // ... dexOptions { incremental = true; preDexLibraries = false javaMaxHeapSize "4g" // 2g should be also OK } }

#!/bin/bash
while read line           
do   
beforeC=$(echo "$line" | cut -f-5 -d';')
sortcolumn=$(echo "$line" | awk -F ";" '{print $6}' | tr -t , "\n" | sort -r -n | xargs | sed 's/ /,/g') 
afterC=$(echo "$line" | cut -f7- -d';')
echo -e $beforeC";"$sortcolumn";"$afterC
done <file 


user@host:/tmp/test$ cat file 
00000000000000;000022233333;2;NONE;true;100,100,5,1,28;UNKNOWN
00000000000000;000022233333;2;NONE;true;99,100,5,1,28;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,99,5,1,28;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,4,1,28;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,4,0,28;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,4,1,27;UNKNOWN

user@host:/tmp/test$ ./sortAColumn.sh 
00000000000000;000022233333;2;NONE;true;100,100,28,5,1;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,99,28,5,1;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,99,28,5,1;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,28,4,1;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,28,4,0;UNKNOWN
00000000000000;000022233333;2;NONE;true;100,100,27,4,1;UNKNOWN

答案 2 :(得分:1)

您的应用程序正在尝试分配更多内存并且正在 OutOfMemory ,因为它无法实现。

确保使用

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

此外,check this google link regarding this error通过检查其堆栈跟踪