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# Toolchain used to create native libraries for robolectric_binary() targets. 22robolectric_toolchain = "//build/toolchain/android:robolectric_$host_cpu" 23 24# NOTE: Because Chrome OS builds may depend on targets built with the Android 25# toolchain, this GNI file may be read and processed from within Chrome OS 26# toolchains. Checking |is_android| here would therefore be too restrictive. 27if (is_android || is_chromeos) { 28 import("//build/config/android/channel.gni") 29 import("//build/config/cast.gni") 30 import("//build/config/clang/clang.gni") 31 import("//build/config/dcheck_always_on.gni") 32 import("//build/toolchain/siso.gni") 33 import("//build_overrides/build.gni") 34 import("abi.gni") 35 36 if (build_with_chromium) { 37 # Some non-chromium projects (e.g. WebRTC) use our build configs 38 # heavily but don't write gclient args files. 39 40 import("//build/config/gclient_args.gni") 41 if (defined(checkout_android_native_support)) { 42 n = "$0x0A" # Newline 43 assert(checkout_android_native_support, 44 "Missing native Android toolchain support. |target_os| in your " + 45 ".gclient configuration file (in the parent directory of " + 46 "src) must include \"android\" and/or \"chromeos\". For " + 47 "example:${n}${n}solutions = [${n}...${n}]${n}" + 48 "target_os=[\"chromeos\"]${n}${n}" + 49 "After adding |target_os| please re-run \"gclient sync\".${n}") 50 } 51 } 52 53 # We are using a separate declare_args block for only this argument so that 54 # we can decide if we have to pull in definitions from the internal config 55 # early. 56 declare_args() { 57 # Enables using the internal Chrome for Android repository. The default 58 # is set from gclient vars, with target_os needed for chromeos. 59 # Can be set to false to disable all internal android things. 60 enable_chrome_android_internal = 61 build_with_chromium && checkout_src_internal && target_os == "android" 62 63 # Experimental new flag for the build system to automatically attempt to 64 # fix missing java deps. This should always be false on bots so they do not 65 # succeed when there are build errors. Devs can override this in args.gn. 66 auto_add_missing_java_deps = false 67 68 # The default to use for android:minSdkVersion for targets that do 69 # not explicitly set it. 70 default_min_sdk_version = 26 71 72 # Static analysis can be either "on" or "off" or "build_server". This 73 # controls how android lint, error-prone, bytecode checks are run. This 74 # needs to be in a separate declare_args as it determines some of the args 75 # in the main declare_args block below. 76 # "on" is the default. 77 # "off" avoids running any static analysis. This is the default for 78 # official builds to reduce build times. Failures in static analysis 79 # would have been caught by other bots. 80 # "build_server" ensures that fast_local_dev_server.py is running and 81 # offloads analysis tasks to it to be run after the build completes. 82 # This is the recommended setting for local development. 83 if (is_official_build) { 84 android_static_analysis = "off" 85 } else { 86 android_static_analysis = "on" 87 } 88 } 89 90 # Our build system no longer supports legacy multidex. 91 min_supported_sdk_version = 21 92 93 assert( 94 default_min_sdk_version >= min_supported_sdk_version, 95 "default_min_sdk_version ($default_min_sdk_version) must be >= min_supported_sdk_version ($min_supported_sdk_version)") 96 97 # Avoid typos when setting android_static_analysis in args.gn. 98 assert(android_static_analysis == "on" || android_static_analysis == "off" || 99 android_static_analysis == "build_server") 100 101 # This configuration has not bot coverage and has broken multiple times. 102 # Warn against it. 103 assert(!(enable_chrome_android_internal && skip_secondary_abi_for_cq)) 104 105 if (enable_chrome_android_internal) { 106 import("//clank/config.gni") 107 } else { 108 import("//build/config/android/sdk.gni") 109 declare_args() { 110 # Which Android SDK to use. 111 android_sdk_release = default_android_sdk_release 112 } 113 } 114 115 if (!defined(default_android_ndk_root)) { 116 default_android_ndk_root = "//third_party/android_toolchain/ndk" 117 if (current_cpu == "riscv64") { 118 # Today (2023-08-30) only the canary Android NDK supports RISC-V64. 119 default_android_ndk_root = "//third_party/android_toolchain_canary/ndk" 120 } 121 default_android_ndk_version = "r25c" 122 default_android_ndk_major_version = 25 123 } else { 124 assert(defined(default_android_ndk_version)) 125 assert(defined(default_android_ndk_major_version)) 126 } 127 128 public_android_sdk_root = "//third_party/android_sdk/public" 129 public_android_sdk_build_tools = 130 "${public_android_sdk_root}/build-tools/34.0.0" 131 public_android_sdk_version = "34" 132 if (android_sdk_release == "u") { 133 default_android_sdk_root = public_android_sdk_root 134 default_android_sdk_version = public_android_sdk_version 135 default_android_sdk_build_tools_version = "34.0.0" 136 public_android_sdk = true 137 } 138 139 # For use downstream when we are building with preview Android SDK 140 if (!defined(final_android_sdk)) { 141 final_android_sdk = public_android_sdk 142 } 143 144 if (!defined(default_lint_android_sdk_root)) { 145 # Purposefully repeated so that downstream can change 146 # default_android_sdk_root without changing lint version. 147 default_lint_android_sdk_root = public_android_sdk_root 148 default_lint_android_sdk_version = 34 149 } 150 151 if (!defined(default_extras_android_sdk_root)) { 152 # Purposefully repeated so that downstream can change 153 # default_android_sdk_root without changing where we load the SDK extras 154 # from. (Google Play services, etc.) 155 default_extras_android_sdk_root = public_android_sdk_root 156 } 157 158 if (!defined(default_android_keystore_path)) { 159 default_android_keystore_path = "//build/android/chromium-debug.keystore" 160 default_android_keystore_name = "chromiumdebugkey" 161 default_android_keystore_password = "chromium" 162 } 163 164 # google_play_services_package contains the path where individual client 165 # targets (e.g. google_play_services_base_java) are located. 166 if (!defined(google_play_services_package)) { 167 google_play_services_package = "//third_party/android_deps" 168 } 169 170 if (!defined(android_protoc_bin)) { 171 android_protoc_bin = "//third_party/android_protoc/protoc" 172 } 173 174 webview_public_framework_dep = 175 "//third_party/android_sdk:public_framework_system_java" 176 if (!defined(webview_framework_dep)) { 177 webview_framework_dep = webview_public_framework_dep 178 } 179 180 assert(defined(default_android_sdk_root), 181 "SDK release " + android_sdk_release + " not recognized.") 182 183 declare_args() { 184 android_ndk_root = default_android_ndk_root 185 android_ndk_version = default_android_ndk_version 186 android_ndk_major_version = default_android_ndk_major_version 187 188 # Android API level for 32 bits platforms 189 android32_ndk_api_level = default_min_sdk_version 190 191 # Android API level for 64 bits platforms 192 android64_ndk_api_level = default_min_sdk_version 193 194 if (default_min_sdk_version < 21) { 195 # Android did not support 64 bit before API 21. 196 android64_ndk_api_level = 21 197 } 198 if (current_cpu == "riscv64" && default_min_sdk_version < 35) { 199 # Android did not support RISC-V64 before API 35. 200 android64_ndk_api_level = 35 201 } 202 203 android_sdk_root = default_android_sdk_root 204 android_sdk_version = default_android_sdk_version 205 android_sdk_build_tools_version = default_android_sdk_build_tools_version 206 207 lint_android_sdk_root = default_lint_android_sdk_root 208 lint_android_sdk_version = default_lint_android_sdk_version 209 210 # Libc++ library directory. Override to use a custom libc++ binary. 211 android_libcpp_lib_dir = "" 212 213 # Android versionCode for android_apk()s that don't explicitly set one. 214 android_default_version_code = "1" 215 216 # Android versionName for android_apk()s that don't explicitly set one. 217 android_default_version_name = "Developer Build" 218 219 # Forced Android versionCode 220 android_override_version_code = "" 221 222 # Forced Android versionName 223 android_override_version_name = "" 224 225 # The path to the keystore to use for signing builds. 226 android_keystore_path = default_android_keystore_path 227 228 # The name of the keystore to use for signing builds. 229 android_keystore_name = default_android_keystore_name 230 231 # The password for the keystore to use for signing builds. 232 android_keystore_password = default_android_keystore_password 233 234 # Mark APKs as android:debuggable="true". 235 debuggable_apks = !is_official_build 236 237 # Set to false to disable the Errorprone compiler. 238 use_errorprone_java_compiler = android_static_analysis != "off" 239 240 # When true, updates all android_aar_prebuilt() .info files during gn gen. 241 # Refer to android_aar_prebuilt() for more details. 242 update_android_aar_prebuilts = false 243 244 # Turns off android lint. 245 disable_android_lint = android_static_analysis == "off" 246 247 # Location of aapt2 used for app bundles. For now, a more recent version 248 # than the one distributed with the Android SDK is required. 249 android_sdk_tools_bundle_aapt2_dir = 250 "//third_party/android_build_tools/aapt2" 251 252 # Causes expectation failures to break the build, otherwise, just warns on 253 # stderr and writes a failure file to $android_configuration_failure_dir: 254 fail_on_android_expectations = false 255 256 # Controls whether proguard obfuscation is enabled for targets 257 # configured to use it. 258 enable_proguard_obfuscation = true 259 260 # Controls whether |short_resource_paths| and |strip_resource_names| are 261 # respected. Useful when trying to analyze APKs using tools that do not 262 # support mapping these names. 263 enable_arsc_obfuscation = true 264 265 # Controls whether |strip_unused_resources| is respected. Useful when trying 266 # to analyze APKs using tools that do not support missing resources from 267 # resources.arsc. 268 enable_unused_resource_stripping = true 269 270 # Controls whether specifying |art_profile_path| automatically adds a binary 271 # baseline profile to the APK/AAB. 272 # Currently disabled while bundletool does not support baseline profiles in 273 # non-base splits. 274 enable_baseline_profiles = false 275 276 # Controls whether specifying |art_profile_path| automatically applies it as 277 # a startup profile to the APK/AAB. 278 # Currently disabled while R8 causes checkdiscard errors due to 279 # methods/classes not being inlined correctly. 280 enable_startup_profiles = false 281 282 # The target to use as the system WebView implementation. 283 if (android_64bit_target_cpu) { 284 if (skip_secondary_abi_for_cq) { 285 system_webview_apk_target = "//android_webview:system_webview_64_apk" 286 } else { 287 system_webview_apk_target = "//android_webview:system_webview_32_64_apk" 288 } 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 # We need a second declare_args block to make sure we are using the overridden 298 # value of the arguments set above. 299 declare_args() { 300 if (defined(default_android_sdk_platform_version)) { 301 android_sdk_platform_version = default_android_sdk_platform_version 302 } else { 303 android_sdk_platform_version = android_sdk_version 304 } 305 306 # Whether java assertions and Preconditions checks are enabled. 307 enable_java_asserts = dcheck_always_on || !is_official_build 308 309 # Reduce build time by using d8 incremental build. 310 enable_incremental_d8 = true 311 312 # Enables trace event injection on Android views with bytecode rewriting. 313 # This adds an additional step on android_app_bundle_module targets that 314 # adds trace events to some methods in android.view.View subclasses. 315 enable_trace_event_bytecode_rewriting = 316 !is_java_debug && android_channel != "stable" 317 } 318 319 assert(!incremental_install || is_java_debug, 320 "incremental_install=true && is_java_debug=false is not supported.") 321 322 # We overwrite system_webview_apk_target if it is an alias 323 if (android_64bit_target_cpu) { 324 system_webview_apk_target = 325 string_replace(system_webview_apk_target, 326 "system_webview_google_apk", 327 "system_webview_google_32_64_apk") 328 } 329 330 # Host stuff ----------------------------------------------------------------- 331 332 # Defines the name the Android build gives to the current host CPU 333 # architecture, which is different than the names GN uses. 334 if (host_cpu == "x64") { 335 android_host_arch = "x86_64" 336 } else if (host_cpu == "x86") { 337 android_host_arch = "x86" 338 } else { 339 assert(false, "Need Android toolchain support for your build CPU arch.") 340 } 341 342 # Defines the name the Android build gives to the current host CPU 343 # architecture, which is different than the names GN uses. 344 if (host_os == "linux") { 345 android_host_os = "linux" 346 } else if (host_os == "mac") { 347 android_host_os = "darwin" 348 } else { 349 assert(false, "Need Android toolchain support for your build OS.") 350 } 351 352 # Directories and files ------------------------------------------------------ 353 # 354 # We define may of the dirs strings here for each output architecture (rather 355 # than just the current one) since these are needed by the Android toolchain 356 # file to define toolchains for all possible targets in one pass. 357 358 android_sdk = 359 "${android_sdk_root}/platforms/android-${android_sdk_platform_version}" 360 android_sdk_build_tools = 361 "${android_sdk_root}/build-tools/$android_sdk_build_tools_version" 362 363 # Path to the SDK's android.jar 364 android_sdk_jar = "$android_sdk/android.jar" 365 366 # Location of libgcc. This is only needed for the current GN toolchain, so we 367 # only need to define the current one, rather than one for every platform 368 # like the toolchain roots. 369 if (current_cpu == "x86") { 370 android_prebuilt_arch = "android-x86" 371 } else if (current_cpu == "arm") { 372 android_prebuilt_arch = "android-arm" 373 } else if (current_cpu == "mipsel") { 374 android_prebuilt_arch = "android-mips" 375 } else if (current_cpu == "x64") { 376 android_prebuilt_arch = "android-x86_64" 377 } else if (current_cpu == "arm64") { 378 android_prebuilt_arch = "android-arm64" 379 } else if (current_cpu == "mips64el") { 380 android_prebuilt_arch = "android-mips64" 381 } else if (current_cpu == "riscv64") { 382 # Place holder for riscv64 support, not tested. 383 android_prebuilt_arch = "android-riscv64" 384 } else { 385 assert(false, "Need android libgcc support for your target arch.") 386 } 387 388 android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" 389 android_ndk_library_path = "$android_toolchain_root/lib64" 390 391 # Point to Chromium's LLVM for tooling. 392 android_tool_prefix = "$clang_base_path/bin/llvm-" 393 android_readelf = "${android_tool_prefix}readobj" 394 android_objcopy = "${android_tool_prefix}objcopy" 395 android_gdbserver = 396 "$android_ndk_root/prebuilt/$android_prebuilt_arch/gdbserver/gdbserver" 397 398 android_sdk_tools_bundle_aapt2 = "${android_sdk_tools_bundle_aapt2_dir}/aapt2" 399 400 # Actions that use java should add this as an input so that they are rebuilt 401 # when the JDK changes. 402 java_path_for_inputs = "//third_party/jdk/current/bin/java.chromium" 403 404 # TODO(crbug.com/1426605): Remove. 405 use_upstream_errorprone_annotations_threadsafe = true 406} 407