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