【问题标题】:Why Gradle gives this error? [duplicate]为什么 Gradle 会出现此错误? [复制]
【发布时间】:2016-07-29 07:21:58
【问题描述】:

我正在构建一个使用 Location Fused Provider 和 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'

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

【问题讨论】:

  • 致电buildToolsVersion "24.0.0"
  • 并添加dexOptions { incremental true javaMaxHeapSize "4g" }

标签: android android-gradle-plugin fusedlocationproviderapi


【解决方案1】:

尝试添加

dexOptions {
        javaMaxHeapSize "4g"
    }

【讨论】:

    【解决方案2】:

    您需要将dexOptions 添加到您的build.gradle

    android {
        compileSdkVersion 24
        buildToolsVersion "23.0.3"
    
        // ...
    
        dexOptions {
            incremental = true;
            preDexLibraries = false
            javaMaxHeapSize "4g" // 2g should be also OK
        }
    }
    

    【讨论】:

      【解决方案3】:

      您的应用程序正在尝试分配更多的内存,并且由于未能成功而导致 OutOfMemory

      确保增加 javaMaxHeapSize 与

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

      另外,check this google link regarding this error 通过检查他们的堆栈跟踪

      【讨论】:

      • 当我把这个条件放在 gradle 中时,这是否意味着我的问题在这个应用程序中永远解决了,或者它只是暂时的,我应该做一些事情来减少内存?
      • 让我们把问题看成一个整体。在这个线程的上下文中,您正在谈论 gradle 内存,它指的是编译时内存。在这种情况下,您只需要增加编译堆,很可能会解决您的编译问题。如果您指的是应用程序内存(堆),是的。您应该始终处理您的内存使用情况,以防止内存泄漏或 OutOfMemory 错误。查看此帖子stackoverflow.com/questions/38592211/…
      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 2022-01-04
      相关资源
      最近更新 更多