【问题标题】:Is r8 enabled on existing project after updating Android studio?更新 Android Studio 后是否在现有项目上启用了 r8?
【发布时间】:2019-04-23 20:46:43
【问题描述】:

我更新了 Android Studio,如果我没记错的话,我的项目默认包含 R8。问题是 r8 仅在默认情况下在新项目上激活,或者更新是否包括对我已经创建的项目的更改?如果没有,我该如何使用它。

【问题讨论】:

  • 希望更新不会。它可能会破坏proguard。不过,您仍然可以轻松切换它
  • 一切正常。但是为什么要打破 proguard 我认为 v8 正在取代它所以我希望 proguard 完全消失
  • R8 不能替代 proguard,因为 R8 是 Google 而 Proguard 是 Guardsquare。即使在不太可能发生的情况下 Google 会取消对 Proguard 的支持,Google 也与 ProGuard 无关,因此实际上无法阻止它。 ProGuard 作为标准可能会被淘汰,但不会被 R8 取代。此外,虽然 R8 具有与 ProGuard 的兼容模式,但同时运行两者可能会破坏一些东西(这就是我上次评论的意思)。此外,R8 目前needs to be enabled manually.
  • 您的链接来自 2018 年,此链接在行为更改中显示“默认启用 R8”,但我是 Android 工作室的新手,我不了解它developer.android.com/studio/releases/gradle-plugin
  • For a given build type, if you set useProguard to false in your app module's build.gradle file, the Android Gradle plugin uses R8 to shrink your app's code for that build type, regardless of whether you disable R8 in your project's gradle.properties file. - 建议它不会覆盖 ProGuard。

标签: android android-studio android-r8


【解决方案1】:

在 Android Studio 3.4 中,所有未禁用 R8 的项目默认使用 R8。 您可以通过以下方式切换到 Proguard:

  • android.enableR8 = false 在 gradle.properties;或
  • useProguard = true 在你的 build.gradle 中。

在 Android Studio 3.5 中,useProguard 标志无效。这意味着始终使用 R8,除非您在 gradle.properties 中添加 android.enableR8=false

【讨论】:

  • 好吧,至少在我的一个应用程序中,R8 不向后兼容 Proguard。 R8 删除了我正在使用的资源,我的应用程序会抛出以下异常:java.lang.IllegalArgumentException: Resource not found: marker_default.png 我无法弄清楚如何正确修改 Proguard 文件R8 所以我使用了这个解决方案。现在一切都像以前一样运行良好,我的项目代码仍然被缩小和混淆。
猜你喜欢
  • 1970-01-01
  • 2017-07-23
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
  • 2013-11-21
  • 1970-01-01
相关资源
最近更新 更多