1# Copyright 2014 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# This file contains common system config stuff for the Android build. 6 7# Some arguments that are needed across all builds that import this file, for 8# example by is_robolectric. 9declare_args() { 10 # Build incremental targets whenever possible. 11 # See //build/android/incremental_install/README.md for more details. 12 incremental_install = false 13} 14 15declare_args() { 16 # Java debug on Android. Having this on enables multidexing, and turning it 17 # off will enable proguard. 18 is_java_debug = is_debug || incremental_install 19} 20 21# These two combinations could theoretically be made to work, but they are 22# not useful and so not worth the effort. 23assert(!(is_java_debug && is_official_build), 24 "Cannot have is_official_build && is_java_debug") 25assert(!(incremental_install && !is_java_debug), 26 "Cannot have incremental_install without is_java_debug") 27 28# Toolchain used to create native libraries for robolectric_binary() targets. 29robolectric_toolchain = "//build/toolchain/android:robolectric_$host_cpu" 30 31if (is_android) { 32 import("//build/config/android/channel.gni") 33 import("//build/config/clang/clang.gni") 34 import("//build/config/dcheck_always_on.gni") 35 import("//build/config/sanitizers/sanitizers.gni") 36 import("//build/toolchain/siso.gni") 37 import("//build_overrides/build.gni") 38 import("abi.gni") 39 40 if (build_with_chromium) { 41 # Some non-chromium projects (e.g. WebRTC) use our build configs 42 # heavily but don't write gclient args files. 43 44 import("//build/config/gclient_args.gni") 45 if (defined(checkout_android)) { 46 n = "$0x0A" # Newline 47 assert(checkout_android, 48 "Missing native Android toolchain support. |target_os| in your " + 49 ".gclient configuration file (in the parent directory of " + 50 "src) must include \"android\". For " + 51 "example:${n}${n}solutions = [${n}...${n}]${n}" + 52 "target_os=[\"android\"]${n}${n}" + 53 "After adding |target_os| please re-run \"gclient sync\".${n}") 54 } 55 } 56 57 # We are using a separate declare_args block for only this argument so that 58 # we can decide if we have to pull in definitions from the internal config 59 # early. 60 declare_args() { 61 # Enables using the internal Chrome for Android repository. The default 62 # is set from gclient vars, with target_os needed for chromeos. 63 # Can be set to false to disable all internal android things. 64 enable_chrome_android_internal = 65 build_with_chromium && checkout_src_internal && target_os == "android" 66 67 # Experimental new flag for the build system to automatically attempt to 68 # fix missing java deps. This should always be false on bots so they do not 69 # succeed when there are build errors. Devs can override this in args.gn. 70 auto_add_missing_java_deps = false 71 72 # The default to use for android:minSdkVersion for targets that do 73 # not explicitly set it. 74 default_min_sdk_version = 26 75 if (is_asan) { 76 default_min_sdk_version = 27 77 } 78 79 # Static analysis can be either "on" or "off" or "build_server". This 80 # controls how android lint, error-prone, bytecode checks are run. This 81 # needs to be in a separate declare_args as it determines some of the args 82 # in the main declare_args block below. 83 # "on" is the default. 84 # "off" avoids running any static analysis. This is the default for 85 # official builds to reduce build times. Failures in static analysis 86 # would have been caught by other bots. 87 # "build_server" ensures that fast_local_dev_server.py is running and 88 # offloads analysis tasks to it to be run after the build completes. 89 # This is the recommended setting for local development. 90 if (is_official_build) { 91 android_static_analysis = "off" 92 } else { 93 android_static_analysis = "on" 94 } 95 96 # Enables teamfooding of new experimental build_server changes. 97 experimental_build_server = false 98 } 99 100 # Our build system no longer supports legacy multidex. 101 min_supported_sdk_version = 21 102 103 # ASAN requires O MR1. 104 # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid/01f8df1ac1a447a8475cdfcb03e8b13140042dbd#running-with-wrapsh-recommended 105 if (is_asan) { 106 min_supported_sdk_version = 27 107 } 108 109 assert( 110 default_min_sdk_version >= min_supported_sdk_version, 111 "default_min_sdk_version ($default_min_sdk_version) must be >= min_supported_sdk_version ($min_supported_sdk_version)") 112 113 # Avoid typos when setting android_static_analysis in args.gn. 114 assert(android_static_analysis == "on" || android_static_analysis == "off" || 115 android_static_analysis == "build_server") 116 117 # This configuration has not bot coverage and has broken multiple times. 118 # Warn against it. 119 assert(!(enable_chrome_android_internal && skip_secondary_abi_for_cq)) 120 121 if (enable_chrome_android_internal) { 122 import("//clank/config.gni") 123 } else { 124 import("//build/config/android/sdk.gni") 125 declare_args() { 126 # Which Android SDK to use. 127 android_sdk_release = default_android_sdk_release 128 } 129 } 130 131 if (!defined(default_android_ndk_root)) { 132 default_android_ndk_root = "//third_party/android_toolchain/ndk" 133 default_android_ndk_version = "r27" 134 } else { 135 assert(defined(default_android_ndk_version)) 136 } 137 138 public_android_sdk_root = "//third_party/android_sdk/public" 139 public_android_sdk_build_tools = 140 "${public_android_sdk_root}/build-tools/35.0.0" 141 public_android_sdk_platform_version = "35" 142 if (android_sdk_release == "v") { 143 default_android_sdk_root = public_android_sdk_root 144 default_android_sdk_platform_version = public_android_sdk_platform_version 145 default_android_sdk_build_tools_version = "35.0.0" 146 public_android_sdk = true 147 } 148 149 # For use downstream when we are building with preview Android SDK 150 if (!defined(final_android_sdk)) { 151 final_android_sdk = public_android_sdk 152 } 153 154 if (!defined(default_lint_android_sdk_root)) { 155 # Purposefully repeated so that downstream can change 156 # default_android_sdk_root without changing lint version. 157 default_lint_android_sdk_root = public_android_sdk_root 158 default_lint_android_sdk_version = public_android_sdk_platform_version 159 } 160 161 if (!defined(default_extras_android_sdk_root)) { 162 # Purposefully repeated so that downstream can change 163 # default_android_sdk_root without changing where we load the SDK extras 164 # from. (Google Play services, etc.) 165 default_extras_android_sdk_root = public_android_sdk_root 166 } 167 168 if (!defined(default_android_keystore_path)) { 169 default_android_keystore_path = "//build/android/chromium-debug.keystore" 170 default_android_keystore_name = "chromiumdebugkey" 171 default_android_keystore_password = "chromium" 172 } 173 174 # google_play_services_package contains the path where individual client 175 # targets (e.g. google_play_services_base_java) are located. 176 if (!defined(google_play_services_package)) { 177 google_play_services_package = "//third_party/android_deps" 178 } 179 180 if (!defined(android_protoc_bin)) { 181 android_protoc_bin = "//third_party/android_build_tools/protoc/cipd/protoc" 182 } 183 184 webview_public_framework_dep = 185 "//third_party/android_sdk:public_framework_system_java" 186 if (!defined(webview_framework_dep)) { 187 webview_framework_dep = webview_public_framework_dep 188 } 189 190 assert(defined(default_android_sdk_root), 191 "SDK release " + android_sdk_release + " not recognized.") 192 193 declare_args() { 194 android_ndk_root = default_android_ndk_root 195 android_ndk_version = default_android_ndk_version 196 197 # Android API level for 32 bits platforms 198 android32_ndk_api_level = default_min_sdk_version 199 200 # Android API level for 64 bits platforms 201 android64_ndk_api_level = default_min_sdk_version 202 203 if (default_min_sdk_version < 21) { 204 # Android did not support 64 bit before API 21. 205 android64_ndk_api_level = 21 206 } 207 if (current_cpu == "riscv64" && default_min_sdk_version < 35) { 208 # Android did not support RISC-V64 before API 35. 209 android64_ndk_api_level = 35 210 } 211 212 android_sdk_root = default_android_sdk_root 213 android_sdk_build_tools_version = default_android_sdk_build_tools_version 214 android_sdk_platform_version = default_android_sdk_platform_version 215 216 lint_android_sdk_root = default_lint_android_sdk_root 217 lint_android_sdk_version = default_lint_android_sdk_version 218 219 # Libc++ library directory. Override to use a custom libc++ binary. 220 android_libcpp_lib_dir = "" 221 222 # Android versionCode for android_apk()s that don't explicitly set one. 223 android_default_version_code = "1" 224 225 # Android versionName for android_apk()s that don't explicitly set one. 226 android_default_version_name = "Developer Build" 227 228 # Forced Android versionCode 229 android_override_version_code = "" 230 231 # Forced Android versionName 232 android_override_version_name = "" 233 234 # The path to the keystore to use for signing builds. 235 android_keystore_path = default_android_keystore_path 236 237 # The name of the keystore to use for signing builds. 238 android_keystore_name = default_android_keystore_name 239 240 # The password for the keystore to use for signing builds. 241 android_keystore_password = default_android_keystore_password 242 243 # Mark APKs as android:debuggable="true". 244 debuggable_apks = !is_official_build 245 246 # Set to false to disable the Errorprone compiler. 247 use_errorprone_java_compiler = android_static_analysis != "off" 248 249 # When true, updates all android_aar_prebuilt() .info files during gn gen. 250 # Refer to android_aar_prebuilt() for more details. 251 update_android_aar_prebuilts = false 252 253 # Turns off android lint. 254 disable_android_lint = android_static_analysis == "off" 255 256 # Location of aapt2 used for app bundles. For now, a more recent version 257 # than the one distributed with the Android SDK is required. 258 android_sdk_tools_bundle_aapt2_dir = 259 "//third_party/android_build_tools/aapt2/cipd" 260 261 # Causes expectation failures to break the build, otherwise, just warns on 262 # stderr and writes a failure file to $android_configuration_failure_dir: 263 fail_on_android_expectations = false 264 265 # Controls whether proguard obfuscation is enabled for targets 266 # configured to use it. 267 enable_proguard_obfuscation = true 268 269 # Controls whether |short_resource_paths| and |strip_resource_names| are 270 # respected. Useful when trying to analyze APKs using tools that do not 271 # support mapping these names. 272 enable_arsc_obfuscation = true 273 274 # Controls whether |strip_unused_resources| is respected. Useful when trying 275 # to analyze APKs using tools that do not support missing resources from 276 # resources.arsc. 277 enable_unused_resource_stripping = true 278 279 # Controls whether specifying |art_profile_path| automatically adds a binary 280 # baseline profile to the APK/AAB. 281 # Currently disabled while bundletool does not support baseline profiles in 282 # non-base splits. 283 enable_baseline_profiles = false 284 285 # Controls whether specifying |art_profile_path| automatically applies it as 286 # a startup profile to the APK/AAB. 287 # Currently disabled while R8 causes checkdiscard errors due to 288 # methods/classes not being inlined correctly. 289 enable_startup_profiles = false 290 291 # The target to use as the system WebView implementation. 292 if (android_64bit_target_cpu) { 293 if (skip_secondary_abi_for_cq) { 294 system_webview_apk_target = "//android_webview:system_webview_64_apk" 295 } else { 296 system_webview_apk_target = "//android_webview:system_webview_32_64_apk" 297 } 298 } else { 299 system_webview_apk_target = "//android_webview:system_webview_apk" 300 } 301 302 # Where to write failed expectations for bots to read. 303 expectations_failure_dir = "$root_build_dir/failed_expectations" 304 } 305 306 if (is_asan) { 307 # Disable lint since increasing min_sdk_version can cause ObsoleteSdkInt warnings. 308 disable_android_lint = true 309 } 310 311 # We need a second declare_args block to make sure we are using the overridden 312 # value of the arguments set above. 313 declare_args() { 314 # Default value for targetSdkVersion for APK and bundle targets. 315 default_target_sdk_version = "34" 316 317 # Whether java assertions and Preconditions checks are enabled. 318 enable_java_asserts = dcheck_always_on || !is_official_build 319 320 # Reduce build time by using d8 incremental build. 321 enable_incremental_d8 = true 322 323 # Enables trace event injection on Android views with bytecode rewriting. 324 # This adds an additional step on android_app_bundle_module targets that 325 # adds trace events to some methods in android.view.View subclasses. 326 enable_trace_event_bytecode_rewriting = 327 !is_java_debug && android_channel != "stable" 328 } 329 330 assert(!incremental_install || is_java_debug, 331 "incremental_install=true && is_java_debug=false is not supported.") 332 333 # We overwrite system_webview_apk_target if it is an alias 334 if (android_64bit_target_cpu) { 335 system_webview_apk_target = 336 string_replace(system_webview_apk_target, 337 "system_webview_google_apk", 338 "system_webview_google_32_64_apk") 339 } 340 341 # Host stuff ----------------------------------------------------------------- 342 343 # Defines the name the Android build gives to the current host CPU 344 # architecture, which is different than the names GN uses. 345 if (host_cpu == "x64" || host_cpu == "arm64") { 346 # Android toolchain on Mac supports both ARM64 and x64 architectures 347 # despite the x86_64 tag in the Darwin name. 348 android_host_arch = "x86_64" 349 } else if (host_cpu == "x86") { 350 android_host_arch = "x86" 351 } else { 352 assert(false, "Need Android toolchain support for your build CPU arch.") 353 } 354 355 # Defines the name the Android build gives to the current host CPU 356 # architecture, which is different than the names GN uses. 357 if (host_os == "linux") { 358 android_host_os = "linux" 359 } else if (host_os == "mac") { 360 android_host_os = "darwin" 361 } else { 362 assert(false, "Need Android toolchain support for your build OS.") 363 } 364 365 # Directories and files ------------------------------------------------------ 366 # 367 # We define may of the dirs strings here for each output architecture (rather 368 # than just the current one) since these are needed by the Android toolchain 369 # file to define toolchains for all possible targets in one pass. 370 371 android_sdk = 372 "${android_sdk_root}/platforms/android-${android_sdk_platform_version}" 373 android_sdk_build_tools = 374 "${android_sdk_root}/build-tools/$android_sdk_build_tools_version" 375 376 # Path to the SDK's android.jar 377 android_sdk_jar = "$android_sdk/android.jar" 378 379 # Location of libgcc. This is only needed for the current GN toolchain, so we 380 # only need to define the current one, rather than one for every platform 381 # like the toolchain roots. 382 if (current_cpu == "x86") { 383 android_prebuilt_arch = "android-x86" 384 } else if (current_cpu == "arm") { 385 android_prebuilt_arch = "android-arm" 386 } else if (current_cpu == "mipsel") { 387 android_prebuilt_arch = "android-mips" 388 } else if (current_cpu == "x64") { 389 android_prebuilt_arch = "android-x86_64" 390 } else if (current_cpu == "arm64") { 391 android_prebuilt_arch = "android-arm64" 392 } else if (current_cpu == "mips64el") { 393 android_prebuilt_arch = "android-mips64" 394 } else if (current_cpu == "riscv64") { 395 # Place holder for riscv64 support, not tested. 396 android_prebuilt_arch = "android-riscv64" 397 } else { 398 assert(false, "Need android libgcc support for your target arch.") 399 } 400 401 android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" 402 android_ndk_library_path = "$android_toolchain_root/lib64" 403 404 # Point to Chromium's LLVM for tooling. 405 android_tool_prefix = "$clang_base_path/bin/llvm-" 406 android_readelf = "${android_tool_prefix}readobj" 407 android_objcopy = "${android_tool_prefix}objcopy" 408 409 android_sdk_tools_bundle_aapt2 = "${android_sdk_tools_bundle_aapt2_dir}/aapt2" 410 411 _common_inputs_for_jre_jdk = [ 412 "//third_party/jdk/current/conf/logging.properties", 413 "//third_party/jdk/current/conf/security/java.security", 414 "//third_party/jdk/current/lib/ct.sym", 415 "//third_party/jdk/current/lib/jrt-fs.jar", 416 "//third_party/jdk/current/lib/jvm.cfg", 417 "//third_party/jdk/current/lib/libawt.so", 418 "//third_party/jdk/current/lib/libawt_headless.so", 419 "//third_party/jdk/current/lib/libawt_xawt.so", 420 "//third_party/jdk/current/lib/libjava.so", 421 "//third_party/jdk/current/lib/libjimage.so", 422 "//third_party/jdk/current/lib/libjli.so", 423 "//third_party/jdk/current/lib/libjsvml.so", 424 "//third_party/jdk/current/lib/libmanagement.so", 425 "//third_party/jdk/current/lib/libmanagement_ext.so", 426 "//third_party/jdk/current/lib/libnet.so", 427 "//third_party/jdk/current/lib/libnio.so", 428 "//third_party/jdk/current/lib/libverify.so", 429 "//third_party/jdk/current/lib/libzip.so", 430 "//third_party/jdk/current/lib/modules", 431 "//third_party/jdk/current/lib/server/classes.jsa", 432 "//third_party/jdk/current/lib/server/libjvm.so", 433 "//third_party/jdk/current/lib/tzdb.dat", 434 ] 435 436 # Actions that use java should add this as inputs so that they are rebuilt 437 # when the JDK changes. 438 java_paths_for_inputs = [ 439 "//third_party/jdk/current/bin/java", 440 "//third_party/jdk/current/bin/java.chromium", 441 ] + _common_inputs_for_jre_jdk 442 443 javac_paths_for_inputs = 444 [ "//third_party/jdk/current/bin/javac" ] + _common_inputs_for_jre_jdk 445 446 kotlinc_paths_for_inputs = [ 447 "//third_party/kotlinc", 448 "//third_party/kotlinc/current/bin/kotlinc", 449 "//third_party/kotlinc/current/lib/jvm-abi-gen.jar", 450 "//third_party/kotlinc/current/lib/annotations-13.0.jar", 451 "//third_party/kotlinc/current/lib/kotlin-compiler.jar", 452 "//third_party/kotlinc/current/lib/kotlin-preloader.jar", 453 "//third_party/kotlinc/current/lib/kotlin-reflect.jar", 454 "//third_party/kotlinc/current/lib/kotlin-script-runtime.jar", 455 "//third_party/kotlinc/current/lib/kotlin-scripting-common.jar", 456 "//third_party/kotlinc/current/lib/kotlin-scripting-compiler-impl.jar", 457 "//third_party/kotlinc/current/lib/kotlin-scripting-compiler.jar", 458 "//third_party/kotlinc/current/lib/kotlin-scripting-jvm.jar", 459 "//third_party/kotlinc/current/lib/kotlin-stdlib.jar", 460 "//third_party/kotlinc/current/lib/kotlinx-coroutines-core-jvm.jar", 461 "//third_party/kotlinc/current/lib/trove4j.jar", 462 ] 463 464 # TODO(crbug.com/40261378): Remove. 465 use_upstream_errorprone_annotations_threadsafe = true 466} 467