1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# TODO(crbug.com.1052397): Remove this and |chromeos_is_browser_only| usage once 6# |is_chromeos| is true in a LaCrOS build. 7import("//build/config/chromeos/ui_mode.gni") 8 9# This file contains common system config stuff for the Android build. 10 11# NOTE: Because Chrome OS builds may depend on targets built with the Android 12# toolchain, this GNI file may be read and processed from within Chrome OS 13# toolchains. Checking |is_android| here would therefore be too restrictive. 14if (is_android || is_chromeos || 15 (is_linux && chromeos_is_browser_only && also_build_ash_chrome)) { 16 import("//build/config/chromecast_build.gni") 17 import("//build_overrides/build.gni") 18 import("abi.gni") 19 20 if (build_with_chromium) { 21 # Some non-chromium projects (e.g. WebRTC) use our build configs 22 # heavily but don't write gclient args files. 23 24 import("//build/config/gclient_args.gni") 25 if (defined(checkout_android_native_support)) { 26 n = "$0x0A" # Newline 27 assert(checkout_android_native_support, 28 "Missing native Android toolchain support. |target_os| in your " + 29 ".gclient configuration file (in the parent directory of " + 30 "src) must include \"android\" and/or \"chromeos\". For " + 31 "example:${n}${n}solutions = [${n}...${n}]${n}" + 32 "target_os=[\"chromeos\"]${n}${n}" + 33 "After adding |target_os| please re-run \"gclient sync\".${n}") 34 } 35 } 36 37 has_chrome_android_internal = 38 exec_script("//build/dir_exists.py", 39 [ rebase_path("//clank", root_build_dir) ], 40 "string") == "True" 41 42 # We are using a separate declare_args block for only this argument so that 43 # we can decide if we have to pull in definitions from the internal config 44 # early. 45 declare_args() { 46 # Enables using the internal Chrome for Android repository. The default 47 # value depends on whether the repository is available, and if it's not but 48 # this argument is manually set to True, the generation will fail. 49 # The main purpose of this argument is to avoid having to maintain 2 50 # repositories to support both public only and internal builds. 51 enable_chrome_android_internal = has_chrome_android_internal 52 53 # The default to use for android:minSdkVersion for targets that do 54 # not explicitly set it. 55 default_min_sdk_version = 21 56 57 # Android API level for 32 bits platforms 58 android32_ndk_api_level = 16 59 60 # Android API level for 64 bits platforms 61 android64_ndk_api_level = 21 62 63 # [WIP] Allows devs to achieve much faster edit-build-install cycles. 64 # Currently only works for ChromeModern apks due to incremental install. 65 # This needs to be in a separate declare_args as it determines some of the 66 # args in the main declare_args block below. 67 android_fast_local_dev = false 68 } 69 70 if (enable_chrome_android_internal) { 71 import("//clank/config.gni") 72 } else { 73 import("//build/config/android/sdk.gni") 74 declare_args() { 75 # Which Android SDK to use. 76 android_sdk_release = default_android_sdk_release 77 } 78 } 79 80 if (!defined(default_android_ndk_root)) { 81 default_android_ndk_root = "//third_party/android_ndk" 82 default_android_ndk_version = "r20" 83 default_android_ndk_major_version = 20 84 } else { 85 assert(defined(default_android_ndk_version)) 86 assert(defined(default_android_ndk_major_version)) 87 } 88 89 public_android_sdk_root = "//third_party/android_sdk/public" 90 if (android_sdk_release == "r") { 91 default_android_sdk_root = public_android_sdk_root 92 default_android_sdk_version = "30" 93 default_android_sdk_build_tools_version = "30.0.1" 94 public_android_sdk = true 95 } 96 97 # For use downstream when we are building with preview Android SDK 98 if (!defined(final_android_sdk)) { 99 final_android_sdk = public_android_sdk 100 } 101 102 if (!defined(default_lint_android_sdk_root)) { 103 # Purposefully repeated so that downstream can change 104 # default_android_sdk_root without changing lint version. 105 default_lint_android_sdk_root = public_android_sdk_root 106 default_lint_android_sdk_version = 30 107 } 108 109 if (!defined(default_extras_android_sdk_root)) { 110 # Purposefully repeated so that downstream can change 111 # default_android_sdk_root without changing where we load the SDK extras 112 # from. (Google Play services, etc.) 113 default_extras_android_sdk_root = public_android_sdk_root 114 } 115 116 if (!defined(default_android_keystore_path)) { 117 default_android_keystore_path = "//build/android/chromium-debug.keystore" 118 default_android_keystore_name = "chromiumdebugkey" 119 default_android_keystore_password = "chromium" 120 } 121 122 # google_play_services_package contains the path where individual client 123 # targets (e.g. google_play_services_base_java) are located. 124 if (!defined(google_play_services_package)) { 125 if (is_chromecast && chromecast_branding != "public") { 126 google_play_services_package = "//chromecast/internal/android/prebuilt/google-play-services-first-party" 127 } else { 128 google_play_services_package = "//third_party/android_deps" 129 } 130 } 131 132 if (!defined(material_design_target)) { 133 material_design_target = 134 "//third_party/android_deps:com_google_android_material_material_java" 135 } 136 137 if (!defined(android_protoc_bin)) { 138 android_protoc_bin = "//third_party/android_protoc/protoc" 139 android_proto_runtime = 140 "//third_party/android_deps:com_google_protobuf_protobuf_javalite_java" 141 } 142 143 webview_public_framework_dep = 144 "//third_party/android_sdk:public_framework_system_java" 145 if (!defined(webview_framework_dep)) { 146 webview_framework_dep = webview_public_framework_dep 147 } 148 149 assert(defined(default_android_sdk_root), 150 "SDK release " + android_sdk_release + " not recognized.") 151 152 declare_args() { 153 android_ndk_root = default_android_ndk_root 154 android_ndk_version = default_android_ndk_version 155 android_ndk_major_version = default_android_ndk_major_version 156 157 android_sdk_root = default_android_sdk_root 158 android_sdk_version = default_android_sdk_version 159 android_sdk_build_tools_version = default_android_sdk_build_tools_version 160 161 lint_android_sdk_root = default_lint_android_sdk_root 162 lint_android_sdk_version = default_lint_android_sdk_version 163 164 # Libc++ library directory. Override to use a custom libc++ binary. 165 android_libcpp_lib_dir = "" 166 167 # Android versionCode for android_apk()s that don't explicitly set one. 168 android_default_version_code = "1" 169 170 # Android versionName for android_apk()s that don't explicitly set one. 171 android_default_version_name = "Developer Build" 172 173 # Forced Android versionCode 174 android_override_version_code = "" 175 176 # Forced Android versionName 177 android_override_version_name = "" 178 179 # The path to the keystore to use for signing builds. 180 android_keystore_path = default_android_keystore_path 181 182 # The name of the keystore to use for signing builds. 183 android_keystore_name = default_android_keystore_name 184 185 # The password for the keystore to use for signing builds. 186 android_keystore_password = default_android_keystore_password 187 188 # Java debug on Android. Having this on enables multidexing, and turning it 189 # off will enable proguard. 190 is_java_debug = is_debug 191 192 # Mark APKs as android:debuggable="true". 193 debuggable_apks = !is_official_build 194 195 # Set to false to disable the Errorprone compiler. 196 # Defaults to false for official builds to reduce build times. 197 # Static analysis failures should have been already caught by normal bots. 198 # Disabled when fast_local_dev is turned on. 199 use_errorprone_java_compiler = !is_official_build && !android_fast_local_dev 200 201 # Build incremental targets whenever possible. 202 # See //build/android/incremental_install/README.md for more details. 203 incremental_install = android_fast_local_dev 204 205 # When true, updates all android_aar_prebuilt() .info files during gn gen. 206 # Refer to android_aar_prebuilt() for more details. 207 update_android_aar_prebuilts = false 208 209 # Turns off android lint. Useful for prototyping or for faster local builds. 210 # Defaults to true for official builds to reduce build times. 211 # Static analysis failures should have been already caught by normal bots. 212 # Disabled when fast_local_dev is turned on. 213 disable_android_lint = is_official_build || android_fast_local_dev 214 215 # Location of aapt2 used for app bundles. For now, a more recent version 216 # than the one distributed with the Android SDK is required. 217 android_sdk_tools_bundle_aapt2_dir = 218 "//third_party/android_build_tools/aapt2" 219 220 # Causes expectation failures to break the build, otherwise, just warns on 221 # stderr and writes a failure file to $android_configuration_failure_dir: 222 fail_on_android_expectations = false 223 224 # Controls whether proguard obfuscation is enabled for targets 225 # configured to use it. 226 enable_proguard_obfuscation = true 227 228 # Controls whether |short_resource_paths| and |strip_resource_names| are 229 # respected. Useful when trying to analyze APKs using tools that do not 230 # support mapping these names. 231 enable_arsc_obfuscation = true 232 233 # The target to use as the system WebView implementation. 234 system_webview_apk_target = "//android_webview:system_webview_apk" 235 } 236 237 # We need a second declare_args block to make sure we are using the overridden 238 # value of the arguments set above. 239 declare_args() { 240 if (defined(default_android_sdk_platform_version)) { 241 android_sdk_platform_version = default_android_sdk_platform_version 242 } else { 243 android_sdk_platform_version = android_sdk_version 244 } 245 246 # Reduce build time by using d8 incremental build. 247 enable_incremental_d8 = true 248 249 # Use hashed symbol names to reduce JNI symbol overhead. 250 use_hashed_jni_names = !is_java_debug 251 252 # Desugar lambdas and interfaces methods using Desugar.jar rather than 253 # D8/R8. D8/R8 will still be used for backported method desugaring. 254 enable_bazel_desugar = true 255 256 # Enables Java library desugaring. 257 # This will cause an extra classes.dex file to appear in every apk. 258 enable_jdk_library_desugaring = true 259 } 260 261 # Host stuff ----------------------------------------------------------------- 262 263 # Defines the name the Android build gives to the current host CPU 264 # architecture, which is different than the names GN uses. 265 if (host_cpu == "x64") { 266 android_host_arch = "x86_64" 267 } else if (host_cpu == "x86") { 268 android_host_arch = "x86" 269 } else { 270 assert(false, "Need Android toolchain support for your build CPU arch.") 271 } 272 273 # Defines the name the Android build gives to the current host CPU 274 # architecture, which is different than the names GN uses. 275 if (host_os == "linux") { 276 android_host_os = "linux" 277 } else if (host_os == "mac") { 278 android_host_os = "darwin" 279 } else { 280 assert(false, "Need Android toolchain support for your build OS.") 281 } 282 283 # Directories and files ------------------------------------------------------ 284 # 285 # We define may of the dirs strings here for each output architecture (rather 286 # than just the current one) since these are needed by the Android toolchain 287 # file to define toolchains for all possible targets in one pass. 288 289 android_sdk = 290 "${android_sdk_root}/platforms/android-${android_sdk_platform_version}" 291 android_sdk_build_tools = 292 "${android_sdk_root}/build-tools/$android_sdk_build_tools_version" 293 294 # Path to the SDK's android.jar 295 android_sdk_jar = "$android_sdk/android.jar" 296 297 # Location of libgcc. This is only needed for the current GN toolchain, so we 298 # only need to define the current one, rather than one for every platform 299 # like the toolchain roots. 300 if (current_cpu == "x86") { 301 android_prebuilt_arch = "android-x86" 302 _binary_prefix = "i686-linux-android" 303 } else if (current_cpu == "arm") { 304 android_prebuilt_arch = "android-arm" 305 _binary_prefix = "arm-linux-androideabi" 306 } else if (current_cpu == "mipsel") { 307 android_prebuilt_arch = "android-mips" 308 _binary_prefix = "mipsel-linux-android" 309 } else if (current_cpu == "x64") { 310 android_prebuilt_arch = "android-x86_64" 311 _binary_prefix = "x86_64-linux-android" 312 } else if (current_cpu == "arm64") { 313 android_prebuilt_arch = "android-arm64" 314 _binary_prefix = "aarch64-linux-android" 315 } else if (current_cpu == "mips64el") { 316 android_prebuilt_arch = "android-mips64" 317 _binary_prefix = "mips64el-linux-android" 318 } else { 319 assert(false, "Need android libgcc support for your target arch.") 320 } 321 322 android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" 323 android_tool_prefix = "$android_toolchain_root/bin/$_binary_prefix-" 324 android_readelf = "${android_tool_prefix}readelf" 325 android_objcopy = "${android_tool_prefix}objcopy" 326 android_gdbserver = 327 "$android_ndk_root/prebuilt/$android_prebuilt_arch/gdbserver/gdbserver" 328 329 android_sdk_tools_bundle_aapt2 = "${android_sdk_tools_bundle_aapt2_dir}/aapt2" 330} 331