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