Skip to content

Commit

Permalink
Android: Using R8 instead of ProGuard for public targets
Browse files Browse the repository at this point in the history
Bug: 908988
Change-Id: Iaaee8124c56945a8769e6d4ff2a0859ef39c1aea
Reviewed-on: https://chromium-review.googlesource.com/c/1355424
Reviewed-by: agrieve <agrieve@chromium.org>
Commit-Queue: Sam Maier <smaier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612439}
  • Loading branch information
Sam Maier authored and Commit Bot committed Nov 29, 2018
1 parent 6befba5 commit 8dc9787
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
8 changes: 6 additions & 2 deletions build/config/android/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ if (is_android || is_chromeos) {
"//third_party/android_build_tools/aapt2/aapt2"

# Use r8 for Java optimization rather than ProGuard.
# This will evenutally be the default. https://crbug.com/872904
experimental_use_r8 = false
# This will evenutally be the default. https://crbug.com/908988
# -1 will turn it on only for public targets, 0 turns it off for all, and 1
# turns it on for all targets.
# TODO(smaier): Once R8 is acceptable for all usages, make this a bool and
# get rid of the use_r8 variable everywhere.
experimental_use_r8 = -1
}

# We need a second declare_args block to make sure we are using the overridden
Expand Down
11 changes: 9 additions & 2 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ if (enable_java_templates) {
])
script = "//build/android/gyp/proguard.py"

_use_r8 = (defined(invoker.use_r8) && invoker.use_r8) ||
experimental_use_r8 == 1

# http://crbug.com/725224. Fix for bots running out of memory.
pool = "//build/toolchain:link_pool($default_toolchain)"

Expand Down Expand Up @@ -980,7 +983,7 @@ if (enable_java_templates) {
"--classpath",
"@FileArg($_rebased_build_config:android:sdk_jars)",
]
if (experimental_use_r8) {
if (_use_r8) {
args += [
"--r8-path",
rebase_path(_r8_path, root_build_dir),
Expand Down Expand Up @@ -1067,7 +1070,9 @@ if (enable_java_templates) {

_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_proguarding_with_r8 = _proguard_enabled && experimental_use_r8
_use_r8 =
(defined(invoker.use_r8) && invoker.use_r8) || experimental_use_r8 == 1
_proguarding_with_r8 = _use_r8 && _proguard_enabled

assert(!(defined(invoker.input_jars) && _proguard_enabled),
"input_jars can't be specified when proguarding a dex.")
Expand Down Expand Up @@ -1107,6 +1112,7 @@ if (enable_java_templates) {
"proguard_mapping_path",
"testonly",
])
use_r8 = _use_r8
inputs = []
if (defined(invoker.inputs)) {
inputs += invoker.inputs
Expand Down Expand Up @@ -3373,6 +3379,7 @@ if (enable_java_templates) {

if (defined(_dex_path)) {
dex("${target_name}__dex") {
forward_variables_from(invoker, [ "use_r8" ])
input_jars = [ _final_jar_path ]
output = _dex_path
deps = [
Expand Down
16 changes: 14 additions & 2 deletions build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,11 @@ if (enable_java_templates) {
deps = _deps
build_config = _build_config
proguard_enabled = true
forward_variables_from(invoker, [ "proguard_configs" ])
forward_variables_from(invoker,
[
"proguard_configs",
"use_r8",
])
output = invoker.output
}
}
Expand Down Expand Up @@ -2451,6 +2455,7 @@ if (enable_java_templates) {
"javac_args",
"loadable_modules",
"no_build_hooks",
"use_r8",
"secondary_abi_loadable_modules",
])
if (_is_bundle_module) {
Expand Down Expand Up @@ -2539,6 +2544,7 @@ if (enable_java_templates) {
forward_variables_from(invoker,
[
"min_sdk_version",
"use_r8",
"dexlayout_profile",
])
proguard_enabled = _proguard_enabled
Expand Down Expand Up @@ -2970,6 +2976,7 @@ if (enable_java_templates) {
"uncompress_shared_libraries",
"uncompress_dex",
"use_chromium_linker",
"use_r8",
"version_code",
"version_name",
"write_asset_list",
Expand Down Expand Up @@ -3072,6 +3079,7 @@ if (enable_java_templates) {
"testonly",
"uncompress_shared_libraries",
"use_chromium_linker",
"use_r8",
"version_code",
"version_name",
"write_asset_list",
Expand Down Expand Up @@ -3888,7 +3896,11 @@ if (enable_java_templates) {
enable_multidex = _enable_multidex
proguard_enabled = true
proguard_mapping_path = _proguard_mapping_path
forward_variables_from(invoker, [ "proguard_jar_path" ])
forward_variables_from(invoker,
[
"proguard_jar_path",
"use_r8",
])
build_config = _build_config

deps = _module_targets + _module_build_config_targets +
Expand Down
16 changes: 12 additions & 4 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1486,8 +1486,10 @@ template("chrome_public_apk_or_module_tmpl") {
load_library_from_apk = _is_modern && chromium_linker_supported

version_name = chrome_version_name
if (!experimental_use_r8) {
if (experimental_use_r8 == 0) {
enable_multidex = true
} else {
use_r8 = true
}
}
}
Expand Down Expand Up @@ -1582,8 +1584,10 @@ template("monochrome_public_apk_or_module_tmpl") {
(!defined(use_trichrome_library) || !use_trichrome_library)

version_name = chrome_version_name
if (!experimental_use_r8) {
if (experimental_use_r8 == 0) {
enable_multidex = true
} else {
use_r8 = true
}
}
}
Expand Down Expand Up @@ -1886,8 +1890,10 @@ android_app_bundle("chrome_modern_public_bundle") {
base_module_target = ":chrome_modern_public_base_module"
if (!is_java_debug) {
proguard_enabled = true
if (!experimental_use_r8) {
if (experimental_use_r8 == 0) {
enable_multidex = true
} else {
use_r8 = true
}
}
enable_language_splits = enable_chrome_language_splits
Expand All @@ -1906,8 +1912,10 @@ android_app_bundle("monochrome_public_bundle") {
base_module_target = ":monochrome_public_base_module"
if (!is_java_debug) {
proguard_enabled = true
if (!experimental_use_r8) {
if (experimental_use_r8 == 0) {
enable_multidex = true
} else {
use_r8 = true
}
proguard_android_sdk_dep = webview_framework_dep
}
Expand Down

0 comments on commit 8dc9787

Please sign in to comment.