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