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 97 # Our build system no longer supports legacy multidex. 98 min_supported_sdk_version = 21 99 100 # ASAN requires O MR1. 101 # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid/01f8df1ac1a447a8475cdfcb03e8b13140042dbd#running-with-wrapsh-recommended 102 if (is_asan) { 103 min_supported_sdk_version = 27 104 } 105 106 assert( 107 default_min_sdk_version >= min_supported_sdk_version, 108 "default_min_sdk_version ($default_min_sdk_version) must be >= min_supported_sdk_version ($min_supported_sdk_version)") 109 110 # Avoid typos when setting android_static_analysis in args.gn. 111 assert(android_static_analysis == "on" || android_static_analysis == "off" || 112 android_static_analysis == "build_server") 113 114 if (enable_chrome_android_internal) { 115 import("//clank/config.gni") 116 } else { 117 import("//build/config/android/sdk.gni") 118 declare_args() { 119 # Which Android SDK to use. 120 android_sdk_release = default_android_sdk_release 121 } 122 } 123 124 if (!defined(default_android_ndk_root)) { 125 default_android_ndk_root = "//third_party/android_toolchain/ndk" 126 default_android_ndk_version = "r27" 127 } else { 128 assert(defined(default_android_ndk_version)) 129 } 130 131 public_android_sdk_root = "//third_party/android_sdk/public" 132 public_android_sdk_build_tools = 133 "${public_android_sdk_root}/build-tools/36.0.0" 134 public_android_sdk_platform_version = "36" 135 if (android_sdk_release == "b") { 136 default_android_sdk_root = public_android_sdk_root 137 default_android_sdk_platform_version = public_android_sdk_platform_version 138 default_android_sdk_build_tools_version = "36.0.0" 139 public_android_sdk = true 140 } 141 142 # For use downstream when we are building with preview Android SDK 143 if (!defined(final_android_sdk)) { 144 final_android_sdk = public_android_sdk 145 } 146 147 if (!defined(default_lint_android_sdk_root)) { 148 # Purposefully repeated so that downstream can change 149 # default_android_sdk_root without changing lint version. 150 default_lint_android_sdk_root = public_android_sdk_root 151 default_lint_android_sdk_version = public_android_sdk_platform_version 152 } 153 154 if (!defined(default_extras_android_sdk_root)) { 155 # Purposefully repeated so that downstream can change 156 # default_android_sdk_root without changing where we load the SDK extras 157 # from. (Google Play services, etc.) 158 default_extras_android_sdk_root = public_android_sdk_root 159 } 160 161 if (!defined(default_android_keystore_path)) { 162 default_android_keystore_path = "//build/android/chromium-debug.keystore" 163 default_android_keystore_name = "chromiumdebugkey" 164 default_android_keystore_password = "chromium" 165 } 166 167 # google_play_services_package contains the path where individual client 168 # targets (e.g. google_play_services_base_java) are located. 169 if (!defined(google_play_services_package)) { 170 google_play_services_package = "//third_party/android_deps" 171 } 172 173 if (!defined(android_protoc_bin)) { 174 android_protoc_bin = "//third_party/android_build_tools/protoc/cipd/protoc" 175 } 176 177 webview_public_framework_dep = 178 "//third_party/android_sdk:public_framework_system_java" 179 if (!defined(webview_framework_dep)) { 180 webview_framework_dep = webview_public_framework_dep 181 } 182 183 assert(defined(default_android_sdk_root), 184 "SDK release " + android_sdk_release + " not recognized.") 185 186 declare_args() { 187 android_ndk_root = default_android_ndk_root 188 android_ndk_version = default_android_ndk_version 189 190 # Android API level for 32 bits platforms 191 android32_ndk_api_level = default_min_sdk_version 192 193 # Android API level for 64 bits platforms 194 android64_ndk_api_level = default_min_sdk_version 195 196 if (default_min_sdk_version < 21) { 197 # Android did not support 64 bit before API 21. 198 android64_ndk_api_level = 21 199 } 200 if (current_cpu == "riscv64" && default_min_sdk_version < 35) { 201 # Android did not support RISC-V64 before API 35. 202 android64_ndk_api_level = 35 203 } 204 205 android_sdk_root = default_android_sdk_root 206 android_sdk_build_tools_version = default_android_sdk_build_tools_version 207 android_sdk_platform_version = default_android_sdk_platform_version 208 209 lint_android_sdk_root = default_lint_android_sdk_root 210 lint_android_sdk_version = default_lint_android_sdk_version 211 212 # Libc++ library directory. Override to use a custom libc++ binary. 213 android_libcpp_lib_dir = "" 214 215 # Android versionCode for android_apk()s that don't explicitly set one. 216 android_default_version_code = "1" 217 218 # Android versionName for android_apk()s that don't explicitly set one. 219 android_default_version_name = "Developer Build" 220 221 # Forced Android versionCode 222 android_override_version_code = "" 223 224 # Forced Android versionName 225 android_override_version_name = "" 226 227 # The path to the keystore to use for signing builds. 228 android_keystore_path = default_android_keystore_path 229 230 # The name of the keystore to use for signing builds. 231 android_keystore_name = default_android_keystore_name 232 233 # The password for the keystore to use for signing builds. 234 android_keystore_password = default_android_keystore_password 235 236 # Mark APKs as android:debuggable="true". 237 debuggable_apks = !is_official_build 238 239 # Set to false to disable the Errorprone compiler. 240 use_errorprone_java_compiler = android_static_analysis != "off" 241 242 # When true, updates all android_aar_prebuilt() .info files during gn gen. 243 # Refer to android_aar_prebuilt() for more details. 244 update_android_aar_prebuilts = false 245 246 # Turns off android lint. 247 disable_android_lint = android_static_analysis == "off" 248 249 # Location of aapt2 used for app bundles. For now, a more recent version 250 # than the one distributed with the Android SDK is required. 251 android_sdk_tools_bundle_aapt2_dir = 252 "//third_party/android_build_tools/aapt2/cipd" 253 254 # Causes expectation failures to break the build, otherwise, just warns on 255 # stderr and writes a failure file to $android_configuration_failure_dir: 256 fail_on_android_expectations = false 257 258 # Controls whether proguard obfuscation is enabled for targets 259 # configured to use it. 260 enable_proguard_obfuscation = true 261 262 # Controls whether |short_resource_paths| and |strip_resource_names| are 263 # respected. Useful when trying to analyze APKs using tools that do not 264 # support mapping these names. 265 enable_arsc_obfuscation = true 266 267 # Controls whether |strip_unused_resources| is respected. Useful when trying 268 # to analyze APKs using tools that do not support missing resources from 269 # resources.arsc. 270 enable_unused_resource_stripping = true 271 272 # Controls whether specifying |art_profile_path| automatically adds a binary 273 # baseline profile to the APK/AAB. 274 # Currently disabled while bundletool does not support baseline profiles in 275 # non-base splits. 276 enable_baseline_profiles = false 277 278 # Controls whether specifying |art_profile_path| automatically applies it as 279 # a startup profile to the APK/AAB. 280 # Currently disabled while R8 causes checkdiscard errors due to 281 # methods/classes not being inlined correctly. 282 enable_startup_profiles = false 283 284 # The target to use as the system WebView implementation. 285 if (defined(android_app_secondary_abi)) { 286 system_webview_apk_target = "//android_webview:system_webview_32_64_apk" 287 } else if (android_64bit_target_cpu) { 288 system_webview_apk_target = "//android_webview:system_webview_64_apk" 289 } else { 290 system_webview_apk_target = "//android_webview:system_webview_apk" 291 } 292 293 # Where to write failed expectations for bots to read. 294 expectations_failure_dir = "$root_build_dir/failed_expectations" 295 } 296 297 if (is_asan) { 298 # Disable lint since increasing min_sdk_version can cause ObsoleteSdkInt warnings. 299 disable_android_lint = true 300 } 301 302 # We need a second declare_args block to make sure we are using the overridden 303 # value of the arguments set above. 304 declare_args() { 305 # Default value for targetSdkVersion for APK and bundle targets. 306 default_target_sdk_version = "35" 307 308 # Whether java assertions and Preconditions checks are enabled. 309 enable_java_asserts = dcheck_always_on || !is_official_build 310 311 # Reduce build time by using d8 incremental build. 312 enable_incremental_d8 = true 313 314 # Enables trace event injection on Android views with bytecode rewriting. 315 # This adds an additional step on android_app_bundle_module targets that 316 # adds trace events to some methods in android.view.View subclasses. 317 enable_trace_event_bytecode_rewriting = 318 !is_java_debug && android_channel != "stable" 319 } 320 321 assert(!incremental_install || is_java_debug, 322 "incremental_install=true && is_java_debug=false is not supported.") 323 324 # We overwrite system_webview_apk_target if it is an alias 325 if (android_64bit_target_cpu) { 326 system_webview_apk_target = 327 string_replace(system_webview_apk_target, 328 "system_webview_google_apk", 329 "system_webview_google_32_64_apk") 330 } 331 332 # Host stuff ----------------------------------------------------------------- 333 334 # Defines the name the Android build gives to the current host CPU 335 # architecture, which is different than the names GN uses. 336 if (host_cpu == "x64" || host_cpu == "arm64") { 337 # Android toolchain on Mac supports both ARM64 and x64 architectures 338 # despite the x86_64 tag in the Darwin name. 339 android_host_arch = "x86_64" 340 } else if (host_cpu == "x86") { 341 android_host_arch = "x86" 342 } else { 343 assert(false, "Need Android toolchain support for your build CPU arch.") 344 } 345 346 # Defines the name the Android build gives to the current host CPU 347 # architecture, which is different than the names GN uses. 348 if (host_os == "linux") { 349 android_host_os = "linux" 350 } else if (host_os == "mac") { 351 android_host_os = "darwin" 352 } else { 353 assert(false, "Need Android toolchain support for your build OS.") 354 } 355 356 # Directories and files ------------------------------------------------------ 357 # 358 # We define may of the dirs strings here for each output architecture (rather 359 # than just the current one) since these are needed by the Android toolchain 360 # file to define toolchains for all possible targets in one pass. 361 362 android_sdk = 363 "${android_sdk_root}/platforms/android-${android_sdk_platform_version}" 364 android_sdk_build_tools = 365 "${android_sdk_root}/build-tools/$android_sdk_build_tools_version" 366 367 # Path to the SDK's android.jar 368 android_sdk_jar = "$android_sdk/android.jar" 369 370 # Location of libgcc. This is only needed for the current GN toolchain, so we 371 # only need to define the current one, rather than one for every platform 372 # like the toolchain roots. 373 if (current_cpu == "x86") { 374 android_prebuilt_arch = "android-x86" 375 } else if (current_cpu == "arm") { 376 android_prebuilt_arch = "android-arm" 377 } else if (current_cpu == "mipsel") { 378 android_prebuilt_arch = "android-mips" 379 } else if (current_cpu == "x64") { 380 android_prebuilt_arch = "android-x86_64" 381 } else if (current_cpu == "arm64") { 382 android_prebuilt_arch = "android-arm64" 383 } else if (current_cpu == "mips64el") { 384 android_prebuilt_arch = "android-mips64" 385 } else if (current_cpu == "riscv64") { 386 # Place holder for riscv64 support, not tested. 387 android_prebuilt_arch = "android-riscv64" 388 } else { 389 assert(false, "Need android libgcc support for your target arch.") 390 } 391 392 android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" 393 android_ndk_library_path = "$android_toolchain_root/lib64" 394 395 # Point to Chromium's LLVM for tooling. 396 android_tool_prefix = "$clang_base_path/bin/llvm-" 397 android_readelf = "${android_tool_prefix}readobj" 398 android_objcopy = "${android_tool_prefix}objcopy" 399 400 android_sdk_tools_bundle_aapt2 = "${android_sdk_tools_bundle_aapt2_dir}/aapt2" 401 402 _common_inputs_for_jre_jdk = [ 403 "//third_party/jdk/current/conf/logging.properties", 404 "//third_party/jdk/current/conf/security/java.security", 405 "//third_party/jdk/current/lib/ct.sym", 406 "//third_party/jdk/current/lib/jrt-fs.jar", 407 "//third_party/jdk/current/lib/jvm.cfg", 408 "//third_party/jdk/current/lib/libawt.so", 409 "//third_party/jdk/current/lib/libawt_headless.so", 410 "//third_party/jdk/current/lib/libawt_xawt.so", 411 "//third_party/jdk/current/lib/libjava.so", 412 "//third_party/jdk/current/lib/libjimage.so", 413 "//third_party/jdk/current/lib/libjli.so", 414 "//third_party/jdk/current/lib/libjsvml.so", 415 "//third_party/jdk/current/lib/libmanagement.so", 416 "//third_party/jdk/current/lib/libmanagement_ext.so", 417 "//third_party/jdk/current/lib/libnet.so", 418 "//third_party/jdk/current/lib/libnio.so", 419 "//third_party/jdk/current/lib/libverify.so", 420 "//third_party/jdk/current/lib/libzip.so", 421 "//third_party/jdk/current/lib/modules", 422 "//third_party/jdk/current/lib/server/classes.jsa", 423 "//third_party/jdk/current/lib/server/libjvm.so", 424 "//third_party/jdk/current/lib/tzdb.dat", 425 ] 426 427 # Actions that use java should add this as inputs so that they are rebuilt 428 # when the JDK changes. 429 java_paths_for_inputs = [ 430 "//third_party/jdk/current/bin/java", 431 "//third_party/jdk/current/bin/java.chromium", 432 ] + _common_inputs_for_jre_jdk 433 434 javac_paths_for_inputs = 435 [ "//third_party/jdk/current/bin/javac" ] + _common_inputs_for_jre_jdk 436 437 kotlinc_paths_for_inputs = [ 438 "//third_party/kotlinc", 439 "//third_party/kotlinc/current/bin/kotlinc", 440 "//third_party/kotlinc/current/lib/jvm-abi-gen.jar", 441 "//third_party/kotlinc/current/lib/annotations-13.0.jar", 442 "//third_party/kotlinc/current/lib/kotlin-compiler.jar", 443 "//third_party/kotlinc/current/lib/kotlin-preloader.jar", 444 "//third_party/kotlinc/current/lib/kotlin-reflect.jar", 445 "//third_party/kotlinc/current/lib/kotlin-script-runtime.jar", 446 "//third_party/kotlinc/current/lib/kotlin-scripting-common.jar", 447 "//third_party/kotlinc/current/lib/kotlin-scripting-compiler-impl.jar", 448 "//third_party/kotlinc/current/lib/kotlin-scripting-compiler.jar", 449 "//third_party/kotlinc/current/lib/kotlin-scripting-jvm.jar", 450 "//third_party/kotlinc/current/lib/kotlin-stdlib.jar", 451 "//third_party/kotlinc/current/lib/kotlinx-coroutines-core-jvm.jar", 452 "//third_party/kotlinc/current/lib/trove4j.jar", 453 ] 454 455 # TODO(crbug.com/40261378): Remove. 456 use_upstream_errorprone_annotations_threadsafe = true 457 458 android_logs = [ "android64_ndk_api_level=${android64_ndk_api_level}" ] 459} 460