aboutsummaryrefslogtreecommitdiff
path: root/build/config/android/config.gni
blob: 1b8352cdef4ab480f81c225e92da8048f36bdc56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# 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
}

# Toolchain used to create native libraries for robolectric_binary() targets.
robolectric_toolchain = "//build/toolchain/android:robolectric_$host_cpu"

# NOTE: Because Chrome OS builds may depend on targets built with the Android
# toolchain, this GNI file may be read and processed from within Chrome OS
# toolchains. Checking |is_android| here would therefore be too restrictive.
if (is_android || is_chromeos) {
  import("//build/config/android/channel.gni")
  import("//build/config/cast.gni")
  import("//build/config/clang/clang.gni")
  import("//build/config/dcheck_always_on.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_native_support)) {
      n = "$0x0A"  # Newline
      assert(checkout_android_native_support,
             "Missing native Android toolchain support. |target_os| in your " +
                 ".gclient configuration file (in the parent directory of " +
                 "src) must include \"android\" and/or \"chromeos\". For " +
                 "example:${n}${n}solutions = [${n}...${n}]${n}" +
                 "target_os=[\"chromeos\"]${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 && checkout_src_internal && target_os == "android"

    # Experimental new flag for the build system to automatically attempt to
    # fix missing java deps. This should always be false on bots so they do not
    # succeed when there are build errors. Devs can override this in args.gn.
    auto_add_missing_java_deps = false

    # The default to use for android:minSdkVersion for targets that do
    # not explicitly set it.
    default_min_sdk_version = 26

    # 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.
    # "on" is the default.
    # "off" avoids running any static analysis. This is the default for
    #     official builds to reduce build times. Failures in static analysis
    #     would have been caught by other bots.
    # "build_server" ensures that fast_local_dev_server.py is running and
    #     offloads analysis tasks to it to be run after the build completes.
    #     This is the recommended setting for local development.
    if (is_official_build) {
      android_static_analysis = "off"
    } else {
      android_static_analysis = "on"
    }
  }

  # Our build system no longer supports legacy multidex.
  min_supported_sdk_version = 21

  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")

  # This configuration has not bot coverage and has broken multiple times.
  # Warn against it.
  assert(!(enable_chrome_android_internal && skip_secondary_abi_for_cq))

  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
    }
  }

  if (!defined(default_android_ndk_root)) {
    default_android_ndk_root = "//third_party/android_toolchain/ndk"
    if (current_cpu == "riscv64") {
      # Today (2023-08-30) only the canary Android NDK supports RISC-V64.
      default_android_ndk_root = "//third_party/android_toolchain_canary/ndk"
    }
    default_android_ndk_version = "r26b"
  } else {
    assert(defined(default_android_ndk_version))
  }

  public_android_sdk_root = "//third_party/android_sdk/public"
  public_android_sdk_build_tools =
      "${public_android_sdk_root}/build-tools/34.0.0"
  public_android_sdk_version = "34"
  if (android_sdk_release == "u") {
    default_android_sdk_root = public_android_sdk_root
    default_android_sdk_version = public_android_sdk_version
    default_android_sdk_build_tools_version = "34.0.0"
    public_android_sdk = true
  }

  # For use downstream when we are building with preview Android SDK
  if (!defined(final_android_sdk)) {
    final_android_sdk = public_android_sdk
  }

  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 = 34
  }

  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_protoc/protoc"
  }

  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_root = default_android_ndk_root
    android_ndk_version = default_android_ndk_version

    # Android API level for 32 bits platforms
    android32_ndk_api_level = default_min_sdk_version

    # Android API level for 64 bits platforms
    android64_ndk_api_level = default_min_sdk_version

    if (default_min_sdk_version < 21) {
      # Android did not support 64 bit before API 21.
      android64_ndk_api_level = 21
    }
    if (current_cpu == "riscv64" && default_min_sdk_version < 35) {
      # Android did not support RISC-V64 before API 35.
      android64_ndk_api_level = 35
    }

    android_sdk_root = default_android_sdk_root
    android_sdk_version = default_android_sdk_version
    android_sdk_build_tools_version = default_android_sdk_build_tools_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"

    # 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

    # Controls whether |short_resource_paths| and |strip_resource_names| are
    # respected. Useful when trying to analyze APKs using tools that do not
    # support mapping these names.
    enable_arsc_obfuscation = true

    # Controls whether |strip_unused_resources| is respected. Useful when trying
    # to analyze APKs using tools that do not support missing resources from
    # resources.arsc.
    enable_unused_resource_stripping = true

    # 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 (android_64bit_target_cpu) {
      if (skip_secondary_abi_for_cq) {
        system_webview_apk_target = "//android_webview:system_webview_64_apk"
      } else {
        system_webview_apk_target = "//android_webview:system_webview_32_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"
  }

  # We need a second declare_args block to make sure we are using the overridden
  # value of the arguments set above.
  declare_args() {
    if (defined(default_android_sdk_platform_version)) {
      android_sdk_platform_version = default_android_sdk_platform_version
    } else {
      android_sdk_platform_version = android_sdk_version
    }

    # 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

    # 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"
  }

  assert(!incremental_install || is_java_debug,
         "incremental_install=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") {
    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 =
      "${android_sdk_root}/platforms/android-${android_sdk_platform_version}"
  android_sdk_build_tools =
      "${android_sdk_root}/build-tools/$android_sdk_build_tools_version"

  # Path to the SDK's android.jar
  android_sdk_jar = "$android_sdk/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"

  # Actions that use java should add this as an input so that they are rebuilt
  # when the JDK changes.
  java_path_for_inputs = "//third_party/jdk/current/bin/java.chromium"

  # TODO(crbug.com/1426605): Remove.
  use_upstream_errorprone_annotations_threadsafe = true
}