简体   繁体   中英

Got OutOfMemoryError after update Android Gradle Plugin to 3.6.1 from 3.5.3 when run unit test

After update to use Android Gradle Plugin 3.6.1 from 3.5.3, our unit test keeps getting OutOfMemoryError exception randomly.

These are the crash logs:

 Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers: java.lang.OutOfMemoryError at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:108) at com.android.ide.common.workers.ExecutorServiceAdapter.close(ExecutorServiceAdapter.kt:118) at kotlin.io.CloseableKt.closeFinally(Closeable.kt:53) at com.android.build.gradle.internal.res.GenerateLibraryRFileTask.doFullTaskAction(GenerateLibraryRFileTask.kt:120) at com.android.build.gradle.internal.tasks.IncrementalTask.handleIncrementalInputs(IncrementalTask.kt:107) at com.android.build.gradle.internal.tasks.IncrementalTask.access$handleIncrementalInputs(IncrementalTask.kt:64) at com.android.build.gradle.internal.tasks.IncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:73)

As my investigation. AGP 3.6.x changed the way to generate the R file. And the crash happens in this line of code: https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/res/GenerateLibraryRFileTask.kt#120

So far, what I have tried are:

  1. Try to play with some gradle flags. But so far, there is no luck.

    • android.enableGradleWorkers=true/false
    • kapt.use.worker.api=true/false
    • kotlin.parallel.tasks.in.project=true/false
    • android.useCompileClasspathLibraryRClasses=false
  2. Play around with some testOptions flags ( https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html ), for example forkEvery, maxParallelForks. But I am not sure it would help, because the failure happens on the building phrase.

    I am trying to get the heapdump but it's kind of difficult because the OOM happens randomly.

    My setup:

    • Gradle version: 6.2.2
    • Android Gradle Plugin: 3.6.1
    • Android SDK Build-Tools 28.0.3 And I run the unit test by the command-line tool. It should not be related to AS.

It will be very appreciated if anyone of you would suggest any solution or direction to investigate

Just for your info. I have to fire an issue too google here https://issuetracker.google.com/u/1/issues/151460310

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM