本文介绍了在 Android Studio 中启用 R8 Shrinker 时超出了 GC 开销限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Android Studio 3.4 (Canary 9),当我构建我的应用程序时,它失败并出现以下错误

I'm using Android Studio 3.4 (Canary 9), when I build my app, it failed with the following error

任务:app:transformClassesAndResourcesWithR8ForDebug

R8 是一个实验功能.如果您遇到任何问题,请提交错误在 https://issuetracker.google.com,使用Shrinker (R8)"作为组件姓名.您可以通过更新 gradle.properties 来禁用 R8'android.enableR8=false'.

R8 is an experimental feature. If you experience any issues, please file a bug at https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can disable R8 by updating gradle.properties with 'android.enableR8=false'.

AGPBI: {"kind":"warning","text":"缺少类:java.lang.instrument.ClassFileTransformer","sources":[{}],"tool":"D8"}

AGPBI: {"kind":"warning","text":"Missing class: java.lang.instrument.ClassFileTransformer","sources":[{}],"tool":"D8"}

任务 :app:transformClassesAndResourcesWithR8ForDebug 失败

Task :app:transformClassesAndResourcesWithR8ForDebug FAILED

FAILURE:构建失败,出现异常.

FAILURE: Build failed with an exception.

  • 出了什么问题:任务:app:transformClassesAndResourcesWithR8ForDebug"的执行失败.

超出 GC 开销限制

当我通过将 android.enableR8=false 放入 gradle.properties 来禁用 R8 时.一切正常.

When I disable R8 by putting android.enableR8=false into gradle.properties. Everything is working fine.

那么如何在不禁用 R8 Shrinker 的情况下修复此错误?因为我真的很想测试 R8 的功能.

So how can I fix this error without disable R8 Shrinker? Because I'm really want to test functionality of R8.

推荐答案

正如您所说,您没有使用任何自定义 JVM 参数,请尝试一下.

As you said you are not using any custom JVM args, try it out.

在您的 gradle.properties 文件中,为 内存设置.例如尝试设置

In your gradle.properties file try several values for memory settings. For example try to set

org.gradle.jvmargs=-Xmx4096m

正如评论部分所建议的:

As suggested by the commented section:

指定用于守护进程的 JVM 参数.

该设置对于调整内存设置特别有用.

The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Xmx1536m

org.gradle.jvmargs=-Xmx1536m

我在我的项目中使用了 R8,一切正常.

I've used R8 in my project and all worked fine.

这篇关于在 Android Studio 中启用 R8 Shrinker 时超出了 GC 开销限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 05:07