# Copyright 2014 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # This file contains common system config stuff for the Android build. # Some arguments that are needed across all builds that import this file, for # example by is_robolectric. declare_args() { # Build incremental targets whenever possible. # See //build/android/incremental_install/README.md for more details. incremental_install = false } declare_args() { # Java debug on Android. Having this on enables multidexing, and turning it # off will enable proguard. is_java_debug = is_debug || incremental_install } # These two combinations could theoretically be made to work, but they are # not useful and so not worth the effort. assert(!(is_java_debug && is_official_build), "Cannot have is_official_build && is_java_debug") assert(!(incremental_install && !is_java_debug), "Cannot have incremental_install without is_java_debug") # Toolchain used to create native libraries for robolectric_binary() targets. robolectric_toolchain = "//build/toolchain/android:robolectric_$host_cpu" if (is_android) { import("//build/config/android/channel.gni") import("//build/config/chrome_build.gni") import("//build/config/clang/clang.gni") import("//build/config/cronet/config.gni") import("//build/config/dcheck_always_on.gni") import("//build/config/sanitizers/sanitizers.gni") import("//build/toolchain/siso.gni") import("//build_overrides/build.gni") import("abi.gni") if (build_with_chromium) { # Some non-chromium projects (e.g. WebRTC) use our build configs # heavily but don't write gclient args files. import("//build/config/gclient_args.gni") if (defined(checkout_android)) { n = "$0x0A" # Newline assert(checkout_android, "Missing native Android toolchain support. |target_os| in your " + ".gclient configuration file (in the parent directory of " + "src) must include \"android\". For " + "example:${n}${n}solutions = [${n}...${n}]${n}" + "target_os=[\"android\"]${n}${n}" + "After adding |target_os| please re-run \"gclient sync\".${n}") } } # We are using a separate declare_args block for only this argument so that # we can decide if we have to pull in definitions from the internal config # early. declare_args() { # Enables using the internal Chrome for Android repository. The default # is set from gclient vars, with target_os needed for chromeos. # Can be set to false to disable all internal android things. enable_chrome_android_internal = build_with_chromium && enable_src_internal && target_os == "android" && !is_cronet_build # The default to use for android:minSdkVersion for targets that do # not explicitly set it. default_min_sdk_version = 29 if (is_cronet_build) { # Cronet's min sdk version support policy is different from the rest of # Chromium; Cronet explicitly supports older devices. default_min_sdk_version = 24 } # Static analysis can be either "on" or "off" or "build_server". This # controls how android lint, error-prone, bytecode checks are run. This # needs to be in a separate declare_args as it determines some of the args # in the main declare_args block below. # "build_server" (default) # Runs static analysis jobs via a daemon process and does not block # on the results. Does not work on bots (requires autoninja.py). # See: https://chromium.googlesource.com/chromium/src/+/main/build/android/docs/static_analysis.md#autoninja-integration # "on" # Runs static analysis as build steps, blocking until they complete. # This mode will fail builds when analysis steps fail, unless # treat_warnings_as_errors=false is set. # "off" # Disables static analysis. Many bots set this so as to not duplicate # the same analysis steps as other bots. android_static_analysis = "default" # Embed a wrap.sh file within apks to set custom environment variables. # Use a comma space-separated list. # E.g.: LD_PRELOAD=foo:bar LD_DEBUG=statistics android_custom_env = "" } enable_wrap_sh = is_hwasan || is_asan || android_custom_env != "" # Make it such that is_official_build sets android_static_analysis="off", but # leaves enable_r8_tracerefs=true. declare_args() { # Controls whether TraceReferences checks are done (for targets with # proguard_enabled=true). enable_r8_tracerefs = android_static_analysis != "off" } if (android_static_analysis == "default") { if (is_official_build) { # Speed up official builds by disabling. Any failures should have already # been caught by other bots. android_static_analysis = "off" } else { android_static_analysis = "build_server" } } if (android_static_analysis == "build_server" && enable_java_templates && getenv("SWARMING_TASK_ID") != "") { # All android bots that can build java targets need to explicitly set # android_static_analysis = "on" or "off" rather than rely on the default # value, because the default value of "build_server" does not work on # bots. This is an assert instead of a dynamic default so that copy # pasting gn args reproduces bot behavior. assert( false, "All android bots must explicitly set android_static_analysis gn arg.") } # Our build system no longer supports legacy multidex. min_supported_sdk_version = 23 # ASAN requires O MR1. # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid/01f8df1ac1a447a8475cdfcb03e8b13140042dbd#running-with-wrapsh-recommended if (is_asan) { min_supported_sdk_version = 27 } assert( default_min_sdk_version >= min_supported_sdk_version, "default_min_sdk_version ($default_min_sdk_version) must be >= min_supported_sdk_version ($min_supported_sdk_version)") # Avoid typos when setting android_static_analysis in args.gn. assert(android_static_analysis == "on" || android_static_analysis == "off" || android_static_analysis == "build_server") if (enable_chrome_android_internal) { import("//clank/config.gni") } else { import("//build/config/android/sdk.gni") declare_args() { # Which Android SDK to use. android_sdk_release = default_android_sdk_release } } android_ndk_root = "//third_party/android_toolchain/ndk" public_android_sdk_root = "//third_party/android_sdk/public" public_android_sdk_platform_version = "37.0" public_android_sdk_build_tools_version = "37.0.0" if (android_sdk_release == "b") { default_android_sdk_root = public_android_sdk_root default_android_sdk_platform_version = public_android_sdk_platform_version default_android_sdk_build_tools_version = public_android_sdk_build_tools_version public_android_sdk = true } if (!defined(default_target_sdk_version)) { default_target_sdk_version = "36" } if (!defined(default_lint_android_sdk_root)) { # Purposefully repeated so that downstream can change # default_android_sdk_root without changing lint version. default_lint_android_sdk_root = public_android_sdk_root default_lint_android_sdk_version = public_android_sdk_platform_version } if (!defined(default_extras_android_sdk_root)) { # Purposefully repeated so that downstream can change # default_android_sdk_root without changing where we load the SDK extras # from. (Google Play services, etc.) default_extras_android_sdk_root = public_android_sdk_root } if (!defined(default_android_keystore_path)) { default_android_keystore_path = "//build/android/chromium-debug.keystore" default_android_keystore_name = "chromiumdebugkey" default_android_keystore_password = "chromium" } # google_play_services_package contains the path where individual client # targets (e.g. google_play_services_base_java) are located. if (!defined(google_play_services_package)) { google_play_services_package = "//third_party/android_deps" } if (!defined(android_protoc_bin)) { android_protoc_bin = "//third_party/android_build_tools/protoc/cipd/protoc" } if (!defined(android_protoc_import_dirs)) { android_protoc_import_dirs = [ "//third_party/protobuf/src" ] } if (!defined(android_protoc_import_files)) { # Add common, internal protobuf imports. android_protoc_import_files = [ "//third_party/protobuf/src/google/protobuf/descriptor.proto", # cpp_features.proto can be used for C++-specific codegen options. While # it's not particularly useful for Java, protos can be written for both # Java and C++, so we need to support it here too in order not to throw # an error. "//third_party/protobuf/src/google/protobuf/cpp_features.proto", ] } webview_public_framework_dep = "//third_party/android_sdk:public_framework_system_java" if (!defined(webview_framework_dep)) { webview_framework_dep = webview_public_framework_dep } assert(defined(default_android_sdk_root), "SDK release " + android_sdk_release + " not recognized.") declare_args() { android_ndk_api_level = default_min_sdk_version if (current_cpu == "riscv64" && default_min_sdk_version < 36) { # Android did not support RISC-V64 before API 36. android_ndk_api_level = 36 } android_sdk_root = default_android_sdk_root android_sdk_build_tools_version = default_android_sdk_build_tools_version android_sdk_platform_version = default_android_sdk_platform_version lint_android_sdk_root = default_lint_android_sdk_root lint_android_sdk_version = default_lint_android_sdk_version # Libc++ library directory. Override to use a custom libc++ binary. android_libcpp_lib_dir = "" # Android versionCode for android_apk()s that don't explicitly set one. android_default_version_code = "1" # Android versionName for android_apk()s that don't explicitly set one. android_default_version_name = "Developer Build" # Forced Android versionCode android_override_version_code = "" # Forced Android versionName android_override_version_name = "" # The path to the keystore to use for signing builds. android_keystore_path = default_android_keystore_path # The name of the keystore to use for signing builds. android_keystore_name = default_android_keystore_name # The password for the keystore to use for signing builds. android_keystore_password = default_android_keystore_password # Mark APKs as android:debuggable="true". debuggable_apks = !is_official_build # Set to false to disable the Errorprone compiler. use_errorprone_java_compiler = android_static_analysis != "off" # When true, updates all android_aar_prebuilt() .info files during gn gen. # Refer to android_aar_prebuilt() for more details. update_android_aar_prebuilts = false # Turns off android lint. disable_android_lint = android_static_analysis == "off" # Location of aapt2 used for app bundles. For now, a more recent version # than the one distributed with the Android SDK is required. android_sdk_tools_bundle_aapt2_dir = "//third_party/android_build_tools/aapt2/cipd" # Causes expectation failures to break the build, otherwise, just warns on # stderr and writes a failure file to $android_configuration_failure_dir: fail_on_android_expectations = false # Controls whether proguard obfuscation is enabled for targets # configured to use it. enable_proguard_obfuscation = true # Enables all resource optimizations (shrinking, shortening paths, stripping # names). optimize_android_resources = !is_java_debug # Controls whether specifying |art_profile_path| automatically adds a binary # baseline profile to the APK/AAB. # Currently disabled while bundletool does not support baseline profiles in # non-base splits. enable_baseline_profiles = false # Controls whether specifying |art_profile_path| automatically applies it as # a startup profile to the APK/AAB. # Currently disabled while R8 causes checkdiscard errors due to # methods/classes not being inlined correctly. enable_startup_profiles = false # The target to use as the system WebView implementation. if (defined(android_app_secondary_abi)) { system_webview_apk_target = "//android_webview:system_webview_32_64_apk" } else if (android_64bit_target_cpu) { system_webview_apk_target = "//android_webview:system_webview_64_apk" } else { system_webview_apk_target = "//android_webview:system_webview_apk" } # Where to write failed expectations for bots to read. expectations_failure_dir = "$root_build_dir/failed_expectations" # Enables rewriting of certain method invocations with overloads that take # an additional argument of type org.chromium.base.task.Location (see # //build/android/location_rewriter). Turned on for "default" and "canary" # channel for tracing. enable_java_location_rewrite = # Do not want to add deps from //base. build_with_chromium && !is_cronet_build && # Do not want the added build-time outside of official builds. is_official_build && (android_channel == "default" || android_channel == "canary") } assert(!optimize_android_resources || !is_java_debug, "optimize_android_resources = true requires is_java_debug = false") if (is_asan) { # Disable lint since increasing min_sdk_version can cause ObsoleteSdkInt # warnings. disable_android_lint = true } assert( android_ndk_api_level >= min_supported_sdk_version, "android_ndk_api_level ($android_ndk_api_level) must be >= min_supported_sdk_version ($min_supported_sdk_version)") # We need a second declare_args block to make sure we are using the overridden # value of the arguments set above. declare_args() { # Whether java assertions and Preconditions checks are enabled. enable_java_asserts = dcheck_always_on || !is_official_build # Reduce build time by using d8 incremental build. enable_incremental_d8 = true # Assemble dex files in tiers to bypass D8 final merge step. tiered_dex_assembly = is_java_debug # Path to the JSON configuration file defining the tiered dex layers. # The JSON file should contain a list of objects, each representing a layer: # { # "name": "layer_name", # "patterns": [ "glob_pattern1", "glob_pattern2" ], # Match target paths # "labels": [ "label1", "label2" ] # Match target labels # } # Targets are matched against layers in the order they are defined. # Unmatched first-party targets fall back to the "other" layer. # Unmatched third-party targets fall back to the "3p" layer. tiered_dex_partitions_file = "//build/config/android/tiered_dex_partitions.json" # Enables trace event injection on Android views with bytecode rewriting. # This adds an additional step on android_app_bundle_module targets that # adds trace events to some methods in android.view.View subclasses. enable_trace_event_bytecode_rewriting = !is_java_debug && android_channel != "stable" } if (tiered_dex_assembly) { tiered_dex_partitions = read_file(tiered_dex_partitions_file, "json") } assert(!incremental_install || is_java_debug, "incremental_install=true && is_java_debug=false is not supported.") assert(!tiered_dex_assembly || is_java_debug, "tiered_dex_assembly=true && is_java_debug=false is not supported.") # We overwrite system_webview_apk_target if it is an alias if (android_64bit_target_cpu) { system_webview_apk_target = string_replace(system_webview_apk_target, "system_webview_google_apk", "system_webview_google_32_64_apk") } # Host stuff ----------------------------------------------------------------- # Defines the name the Android build gives to the current host CPU # architecture, which is different than the names GN uses. if (host_cpu == "x64" || host_cpu == "arm64") { # Android toolchain on Mac supports both ARM64 and x64 architectures # despite the x86_64 tag in the Darwin name. android_host_arch = "x86_64" } else if (host_cpu == "x86") { android_host_arch = "x86" } else { assert(false, "Need Android toolchain support for your build CPU arch.") } # Defines the name the Android build gives to the current host CPU # architecture, which is different than the names GN uses. if (host_os == "linux") { android_host_os = "linux" } else if (host_os == "mac") { android_host_os = "darwin" } else { assert(false, "Need Android toolchain support for your build OS.") } # Directories and files ------------------------------------------------------ # # We define may of the dirs strings here for each output architecture (rather # than just the current one) since these are needed by the Android toolchain # file to define toolchains for all possible targets in one pass. android_sdk_platform_root = "${android_sdk_root}/platforms/android-${android_sdk_platform_version}" public_android_sdk_platform_root = "${public_android_sdk_root}/platforms/android-${public_android_sdk_platform_version}" android_sdk_build_tools = "${android_sdk_root}/build-tools/$android_sdk_build_tools_version" public_android_sdk_build_tools = "${public_android_sdk_root}/build-tools/$public_android_sdk_build_tools_version" # Path to the SDK's android.jar android_sdk_jar = "$android_sdk_platform_root/android.jar" public_android_sdk_jar = "$public_android_sdk_platform_root/android.jar" # Location of libgcc. This is only needed for the current GN toolchain, so we # only need to define the current one, rather than one for every platform # like the toolchain roots. if (current_cpu == "x86") { android_prebuilt_arch = "android-x86" } else if (current_cpu == "arm") { android_prebuilt_arch = "android-arm" } else if (current_cpu == "mipsel") { android_prebuilt_arch = "android-mips" } else if (current_cpu == "x64") { android_prebuilt_arch = "android-x86_64" } else if (current_cpu == "arm64") { android_prebuilt_arch = "android-arm64" } else if (current_cpu == "mips64el") { android_prebuilt_arch = "android-mips64" } else if (current_cpu == "riscv64") { # Place holder for riscv64 support, not tested. android_prebuilt_arch = "android-riscv64" } else { assert(false, "Need android libgcc support for your target arch.") } android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" android_ndk_library_path = "$android_toolchain_root/lib64" # Point to Chromium's LLVM for tooling. android_tool_prefix = "$clang_base_path/bin/llvm-" android_readelf = "${android_tool_prefix}readobj" android_objcopy = "${android_tool_prefix}objcopy" android_sdk_tools_bundle_aapt2 = "${android_sdk_tools_bundle_aapt2_dir}/aapt2" _common_inputs_for_jre_jdk = [ "//third_party/jdk/current/conf/logging.properties", "//third_party/jdk/current/conf/security/java.security", "//third_party/jdk/current/lib/ct.sym", "//third_party/jdk/current/lib/jrt-fs.jar", "//third_party/jdk/current/lib/jvm.cfg", "//third_party/jdk/current/lib/libawt.so", "//third_party/jdk/current/lib/libawt_headless.so", "//third_party/jdk/current/lib/libawt_xawt.so", "//third_party/jdk/current/lib/libjava.so", "//third_party/jdk/current/lib/libjimage.so", "//third_party/jdk/current/lib/libjli.so", "//third_party/jdk/current/lib/libjsvml.so", "//third_party/jdk/current/lib/libmanagement.so", "//third_party/jdk/current/lib/libmanagement_ext.so", "//third_party/jdk/current/lib/libnet.so", "//third_party/jdk/current/lib/libnio.so", "//third_party/jdk/current/lib/libverify.so", "//third_party/jdk/current/lib/libzip.so", "//third_party/jdk/current/lib/modules", "//third_party/jdk/current/lib/server/classes.jsa", "//third_party/jdk/current/lib/server/libjvm.so", "//third_party/jdk/current/lib/tzdb.dat", ] # Actions that use java should add this as inputs so that they are rebuilt # when the JDK changes. java_paths_for_inputs = [ "//third_party/jdk/current/bin/java", "//third_party/jdk/current/bin/java.chromium", ] + _common_inputs_for_jre_jdk javac_paths_for_inputs = [ "//third_party/jdk/current/bin/javac" ] + _common_inputs_for_jre_jdk kotlinc_paths_for_inputs = [ "//third_party/kotlinc", "//third_party/kotlinc/current/bin/kotlinc", "//third_party/kotlinc/current/lib/jvm-abi-gen.jar", "//third_party/kotlinc/current/lib/annotations-13.0.jar", "//third_party/kotlinc/current/lib/kotlin-compiler.jar", "//third_party/kotlinc/current/lib/kotlin-preloader.jar", "//third_party/kotlinc/current/lib/kotlin-reflect.jar", "//third_party/kotlinc/current/lib/kotlin-script-runtime.jar", "//third_party/kotlinc/current/lib/kotlin-scripting-common.jar", "//third_party/kotlinc/current/lib/kotlin-scripting-compiler-impl.jar", "//third_party/kotlinc/current/lib/kotlin-scripting-compiler.jar", "//third_party/kotlinc/current/lib/kotlin-scripting-jvm.jar", "//third_party/kotlinc/current/lib/kotlin-stdlib.jar", "//third_party/kotlinc/current/lib/kotlinx-coroutines-core-jvm.jar", ] android_logs = [ "android_ndk_api_level=${android_ndk_api_level}" ] }