blob: e4d85aef1f6cc306092623326af82c30f209441d [file] [log] [blame]
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//android_webview/variables.gni")
import("//base/android/linker/config.gni")
import("//build/config/android/extract_unwind_tables.gni")
import("//build/config/android/rules.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/locales.gni")
import("//build/util/version.gni")
import("//chrome/android/chrome_common_shared_library.gni")
import("//chrome/android/features/dev_ui/dev_ui_module.gni")
import("//chrome/common/features.gni")
import("//device/vr/buildflags/buildflags.gni")
import("//weblayer/variables.gni")
import("channel.gni")
default_chrome_public_jinja_variables = [
"channel=$android_channel",
"enable_vr=$enable_vr",
"include_arcore_manifest_flag=false",
]
# Enable stack unwinding only on official build with specific channels. It is
# not enabled on non-official builds to not affect build time for developers.
# The unwind file is ~2MB in apk, which is fine for Canary.
_add_unwind_tables_in_chrome_32bit_apk =
is_official_build && (target_cpu == "arm" || target_cpu == "arm64") &&
(android_channel == "default" || android_channel == "canary" ||
android_channel == "dev")
# A template used to declare any target that will implement a full Chromium
# or Chrome application, either as an APK, or an app bundle module.
#
# Variables:
# target_type: Either 'android_apk' or 'android_app_bundle_module'.
# apk_name: For APK target types, the final APK name without a suffix.
# is_base_module: For bundle module target types, true iff this is a base
# application module, instead of a feature module.
# android_manifest: Application manifest path.
# android_manifest_dep: Name of target generating the android_manifest.
# shared_libraries: List of native shared libraries targets to include in
# the final target (e.g. [ ":libchrome" ]).
# add_unwind_tables_in_apk: Optional. If true, add the unwind tables to the
# final APK or bundle.
# is_modern: If true, indicates this corresponds to a chrome_modern_XXX
# target that can only run on Android L-M.
# is_monochrome: Indicates that this target contains chrome and webview
# packaged together and can only run on Android N+.
# is_trichrome: Indicates this target relies on a trichrome static library
# target and can only run on Android P+.
# png_to_webp: Optional. If true, convert image resources to webp format.
# requires Android K+, since these were not supported by Android properly
# before 4.3.0.
# load_library_from_apk: Optional. If true, native libraries will be loaded
# directly from the APK (and stored zipaligned and uncompressed). This
# requires either the Chromium linker, or Android M+.
# version_name: Application version name (e.g. "Developer Build").
#
# Plus all other variables accepted by android_apk() or
# android_app_bundle_module(), depending on the target type.
#
template("chrome_public_common_apk_or_module_tmpl") {
assert(
invoker.target_type == "android_apk" ||
invoker.target_type == "android_app_bundle_module" ||
invoker.target_type == "instrumentation_test_apk",
"Invalid target_type definition, should be 'android_apk' or 'android_app_bundle_module'")
_is_modern = defined(invoker.is_modern) && invoker.is_modern
_is_monochrome = defined(invoker.is_monochrome) && invoker.is_monochrome
_is_trichrome = defined(invoker.is_trichrome) && invoker.is_trichrome
_is_64_bit_browser =
defined(invoker.is_64_bit_browser) && invoker.is_64_bit_browser
not_needed([
"_is_modern",
"_is_64_bit_browser",
])
assert(!(_is_monochrome && _is_trichrome),
"Cannot be both trichrome and monochrome!")
assert(_is_trichrome == defined(invoker.static_library_provider),
"If trichrome library is used, static_library_provider must be set " +
"so that a dep can be added on the library APK.")
# Adds unwind table asset to the chrome apk for the given library target. This
# is not part of generic apk assets target since it depends on the main shared
# library of the apk, to extract unwind tables.
if (defined(invoker.add_unwind_tables_in_apk)) {
_add_unwind_tables = invoker.add_unwind_tables_in_apk
} else {
_needs_32bit_lib =
target_cpu == "arm" ||
(_is_monochrome && target_cpu == "arm64" && !_is_64_bit_browser)
_add_unwind_tables =
_needs_32bit_lib && _add_unwind_tables_in_chrome_32bit_apk &&
((android_64bit_target_cpu &&
defined(invoker.secondary_abi_shared_libraries)) ||
(!android_64bit_target_cpu && defined(invoker.shared_libraries)))
}
if (_add_unwind_tables) {
_unwind_asset_target = "${target_name}__unwind_assets"
unwind_table_asset(_unwind_asset_target) {
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
if (defined(invoker.shared_library_for_unwind_asset)) {
library_target = invoker.shared_library_for_unwind_asset
} else {
if (_is_monochrome || _is_trichrome) {
library_target = "monochrome"
} else {
library_target = "chrome"
}
}
if (android_64bit_target_cpu) {
deps = [ "//chrome/android:lib${library_target}($android_secondary_abi_toolchain)" ]
} else {
deps = [ "//chrome/android:lib${library_target}" ]
}
}
} else if (defined(invoker.shared_library_for_unwind_asset)) {
not_needed(invoker, [ "shared_library_for_unwind_asset" ])
}
if (!defined(invoker.target_type)) {
_target_type = "android_apk"
} else {
_target_type = invoker.target_type
}
if (defined(invoker.enable_multidex)) {
_enable_multidex = invoker.enable_multidex
} else {
_enable_multidex = is_java_debug
}
target(_target_type, target_name) {
forward_variables_from(invoker, "*")
if (defined(shared_resources_whitelist_target)) {
shared_resources_allowlist_target = shared_resources_whitelist_target
shared_resources_allowlist_locales = shared_resources_whitelist_locales
}
if (_is_trichrome) {
min_sdk_version = 29
} else if (_is_monochrome) {
min_sdk_version = 24
} else if (_is_modern) {
min_sdk_version = 21
} else {
min_sdk_version = 19
}
target_sdk_version = android_sdk_version
# Match drawables, but not mipmaps.
resource_exclusion_regex = "drawable[^/]*-xxxhdpi"
if (min_sdk_version >= 21) {
# Resources used by AndroidManifest.xml only for pre-21.
resource_exclusion_regex += "|app_single_page_icon"
}
# Exception rationale in https://crbug.com/691733.
resource_exclusion_exceptions = [
"*shadow*", # Combination of gradient & transparency cause pixelation.
"*.9.*", # Most nine-patches contain shadows.
"*ic_file_download_white*", # Bottom edge seems misaligned.
"*ic_lock.*", # Bottom edge seems misaligned.
"*ic_group_*", # Appear only in xxxhdpi.
]
if (!_is_monochrome) {
product_config_java_packages = [ "org.chromium.chrome.browser" ]
}
# Use zh-TW strings for zh-HK (https://crbug.com/780847).
if (!defined(support_zh_hk)) {
support_zh_hk = true
}
# Android supports webp transparent resources properly since API level 18,
# so this can only be activated for modern ones (which target API >= 21).
if (!defined(png_to_webp)) {
png_to_webp = !is_java_debug
}
# Removes metadata needed for Resources.getIdentifier("resource_name").
strip_resource_names = !is_java_debug
short_resource_paths = true
if ((defined(shared_libraries) && shared_libraries != []) ||
(defined(secondary_abi_shared_libraries) &&
secondary_abi_shared_libraries != [])) {
_native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
native_lib_version_rule = "//build/util:chrome_version_json"
}
if (!defined(aapt_locale_allowlist)) {
if (target_type == "android_apk") {
# For APKs, do not include the resource strings files from our
# omitted locale list in order to save size.
aapt_locale_allowlist = android_apk_locales
} else {
# For bundles, only include resource strings files from our full
# locale list, but nothing more.
aapt_locale_allowlist = locales
# zh_hk is supported in Android bundles.
support_zh_hk = false
}
}
if (!_is_monochrome && !_is_trichrome) {
deps += [
"//chrome/android:chrome_public_v8_assets",
"//components/crash/core/app:chrome_crashpad_handler_named_as_so",
"//third_party/icu:icu_assets",
]
if (!defined(loadable_modules)) {
loadable_modules = []
}
loadable_modules += [ "$root_out_dir/libchrome_crashpad_handler.so" ]
}
if (_enable_multidex) {
enable_multidex = true
if (_target_type == "android_apk") {
if (!defined(negative_main_dex_globs)) {
negative_main_dex_globs = [
"*ApplicationStatus*", # Doesn't work in non-browser process.
"*ChromeActivity*", # Pulls in the world; ensure it stays out.
"*GoogleApiAvailability*", # Play Services only in browser process.
"*R\$*", # Should not use resources from non-browser process.
]
}
# Allow targets to append to the default list.
if (defined(extra_negative_main_dex_globs)) {
negative_main_dex_globs += extra_negative_main_dex_globs
}
}
}
if (dfmify_dev_ui && (_target_type == "android_apk" ||
_target_type == "instrumentation_test_apk")) {
# Dev UI is a feature in a DFM, and APKs don't use DFMs. To make the code
# available for APKs add a dependency on it.
deps += [ "//chrome/android/features/dev_ui:java" ]
}
if (!is_java_debug) {
proguard_enabled = true
if (!defined(proguard_configs)) {
proguard_configs = []
}
proguard_configs += [
"//chrome/android/java/proguard.flags",
"//base/android/proguard/chromium_apk.flags",
"//base/android/proguard/chromium_code.flags",
]
if (enable_proguard_obfuscation) {
proguard_configs +=
[ "//base/android/proguard/enable_obfuscation.flags" ]
} else {
proguard_configs +=
[ "//base/android/proguard/disable_all_obfuscation.flags" ]
}
}
if (!defined(use_chromium_linker)) {
use_chromium_linker = chromium_linker_supported
}
if (use_chromium_linker) {
if (!defined(load_library_from_apk)) {
# Whether native libraries should be loaded from within the apk.
# Only attempt loading the library from the APK for 64 bit devices
# until the number of 32 bit devices which don't support this
# approach falls to a minimal level - http://crbug.com/390618.
load_library_from_apk = chromium_linker_supported &&
(current_cpu == "arm64" || current_cpu == "x64")
}
}
if (_target_type == "android_apk") {
command_line_flags_file = "chrome-command-line"
}
if (!_is_trichrome) {
product_version_resources_dep =
"//chrome/android:product_version_resources"
}
if (defined(_unwind_asset_target)) {
deps += [ ":$_unwind_asset_target" ]
}
deps += [ "//chrome/android:chrome_all_java" ]
if (!defined(version_code)) {
if (_is_trichrome) {
version_code = trichrome_version_code
} else if (_is_monochrome) {
version_code = monochrome_version_code
} else if (_is_modern) {
version_code = chrome_modern_version_code
} else {
# For chrome without the modern design, used on pre-L devices
version_code = chrome_version_code
}
}
}
}
# The equivalent of chrome_common_apk_or_module_tmpl for all builds of
# monochrome and trichrome chrome.
# Variables:
# use_trichrome_library: Specifies that this target depends on a trichrome
# static library target to provide certain shared library deps, and that
# this target should not package webview deps.
template("monochrome_public_common_apk_or_module_tmpl") {
chrome_public_common_apk_or_module_tmpl(target_name) {
_overrides = {
_is_bundle_module = defined(invoker.target_type) &&
invoker.target_type == "android_app_bundle_module"
if (_is_bundle_module) {
assert(
defined(invoker.is_base_module),
"_is_bundle_module is true but the invoker does not define is_base_module!")
}
if (defined(invoker.enable_multidex)) {
_enable_multidex = invoker.enable_multidex
} else {
_enable_multidex = is_java_debug
}
is_trichrome = defined(invoker.use_trichrome_library) &&
invoker.use_trichrome_library
is_monochrome = !is_trichrome
shared_libraries = []
if (defined(invoker.shared_libraries)) {
shared_libraries += invoker.shared_libraries
}
secondary_abi_shared_libraries = []
if (defined(invoker.secondary_abi_shared_libraries)) {
secondary_abi_shared_libraries += invoker.secondary_abi_shared_libraries
}
loadable_modules = []
if (defined(invoker.loadable_modules)) {
loadable_modules = invoker.loadable_modules
}
secondary_abi_loadable_modules = []
if (defined(invoker.secondary_abi_loadable_modules)) {
secondary_abi_loadable_modules = invoker.secondary_abi_loadable_modules
}
native_lib_placeholders = []
if (defined(invoker.native_lib_placeholders)) {
native_lib_placeholders = invoker.native_lib_placeholders
}
secondary_native_lib_placeholders = []
if (defined(invoker.secondary_native_lib_placeholders)) {
secondary_native_lib_placeholders =
invoker.secondary_native_lib_placeholders
}
deps = [
"//chrome/android:chrome_public_non_pak_assets",
"//components/crash/android:handler_java",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (_is_bundle_module && invoker.is_base_module && enable_arcore) {
# AR DFM is disabled - bring in the ar_java target along with ARCore SDK
# and set the loadable_modules / secondary_abi_loadable_modules to what
# would be brought in by the module.
# This needs to happen for monochrome & trichrome builds of base module if ARCore is enabled.
deps += [
"//chrome/browser/android/vr:ar_java",
"//third_party/arcore-android-sdk-client:com_google_ar_core_java",
]
_libarcore_dir = get_label_info(
"//third_party/arcore-android-sdk-client:com_google_ar_core_java($default_toolchain)",
"target_out_dir") + "/com_google_ar_core_java/jni"
if (android_64bit_target_cpu) {
if (invoker.is_64_bit_browser) {
loadable_modules +=
[ "$_libarcore_dir/arm64-v8a/libarcore_sdk_c.so" ]
} else {
secondary_abi_loadable_modules +=
[ "$_libarcore_dir/armeabi-v7a/libarcore_sdk_c.so" ]
}
} else {
loadable_modules +=
[ "$_libarcore_dir/armeabi-v7a/libarcore_sdk_c.so" ]
}
}
if (is_monochrome) {
product_config_java_packages = [
"org.chromium.chrome.browser",
webview_product_config_java_package,
]
if (webview_includes_weblayer) {
product_config_java_packages +=
[ weblayer_product_config_java_package ]
}
# Flag whether additional deps and libs should be included for each ABI.
_include_primary_support = false
_include_secondary_support = false
if (android_64bit_target_cpu) {
# Build //android_webview:monochrome with the opposite bitness that
# Chrome runs in.
if (invoker.is_64_bit_browser) {
_include_primary_support = true
shared_libraries += [ "//chrome/android:libmonochrome_64" ]
if (invoker.include_32_bit_webview) {
secondary_abi_shared_libraries += [ "//android_webview:monochrome_64($android_secondary_abi_toolchain)" ]
_include_secondary_support = true
}
} else {
secondary_abi_shared_libraries +=
[ "//chrome/android:monochrome_secondary_abi_lib" ]
_include_secondary_support = true
if (invoker.include_64_bit_webview) {
shared_libraries += [ "//android_webview:monochrome" ]
_include_primary_support = true
}
}
} else {
shared_libraries += [ "//chrome/android:libmonochrome" ]
_include_primary_support = true
}
deps += [
"//android_webview/glue",
"//android_webview/nonembedded:nonembedded_java",
"//chrome/android:monochrome_java",
]
if (_include_primary_support) {
deps += [
"//android_webview:monochrome_webview_primary_abi_assets",
"//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline",
]
loadable_modules +=
[ "$root_out_dir/libcrashpad_handler_trampoline.so" ]
}
if (_include_secondary_support) {
_trampoline =
"//third_party/crashpad/crashpad/handler:" +
"crashpad_handler_trampoline($android_secondary_abi_toolchain)"
deps += [
"//android_webview:monochrome_webview_secondary_abi_assets",
_trampoline,
]
_secondary_out_dir = get_label_info(_trampoline, "root_out_dir")
secondary_abi_loadable_modules +=
[ "$_secondary_out_dir/libcrashpad_handler_trampoline.so" ]
}
if (defined(invoker.alternative_android_sdk_dep)) {
alternative_android_sdk_dep = invoker.alternative_android_sdk_dep
} else {
alternative_android_sdk_dep = webview_framework_dep
}
if (defined(invoker.app_as_shared_lib)) {
app_as_shared_lib = invoker.app_as_shared_lib
} else {
app_as_shared_lib = true
}
_pak_prefix = "monochrome"
}
if (is_trichrome) {
# Include placeholder libraries to make Chrome multiarch in the same way
# as Monochrome, even though Chrome only runs with one of the two
# bitnesses. This allows the "32-bit" and "64-bit" versions of Chrome to
# depend on their respective versions of the shared library APK even
# though they're functionally the same.
if (android_64bit_target_cpu) {
if (invoker.is_64_bit_browser) {
native_lib_placeholders += [ "libdummy.so" ]
if (invoker.include_32_bit_webview) {
secondary_native_lib_placeholders += [ "libdummy.so" ]
}
} else {
secondary_native_lib_placeholders += [ "libdummy.so" ]
if (invoker.include_64_bit_webview) {
native_lib_placeholders += [ "libdummy.so" ]
}
}
} else {
native_lib_placeholders += [ "libdummy.so" ]
}
_pak_prefix = "trichrome_chrome"
}
use_chromium_linker = is_trichrome && chromium_linker_supported
use_modern_linker = use_chromium_linker
if (build_hwasan_splits && android_64bit_target_cpu &&
invoker.is_64_bit_browser) {
_hwasan_toolchain =
"//build/toolchain/android:android_clang_arm64_hwasan"
shared_libraries +=
[ "//chrome/android:libmonochrome_64($_hwasan_toolchain)" ]
if (use_chromium_linker) {
shared_libraries += [
"//base/android/linker:chromium_android_linker($_hwasan_toolchain)",
]
}
}
# Resources config for blocklisting resource names from obfuscation
if (defined(invoker.resources_config_path)) {
resources_config_path = invoker.resources_config_path
} else {
resources_config_path = "//android_webview/aapt2.config"
}
if (defined(invoker.never_incremental)) {
never_incremental = invoker.never_incremental
} else if (!defined(invoker.target_type) ||
invoker.target_type == "android_apk") {
# Incremental install doesn't work for monochrome. See crbug.com/663492.
never_incremental = true
}
# Strip xml namespaces for monochrome. This should only be done for apks
# targeting API > 21 which for chrome is only Monochrome. This is due to
# how android public and private resource ids are namespaced.
if (defined(invoker.no_xml_namespaces)) {
no_xml_namespaces = invoker.no_xml_namespaces
} else {
no_xml_namespaces = true
}
# Configrations to make android load shared library from APK.
if (defined(invoker.uncompress_shared_libraries)) {
uncompress_shared_libraries = invoker.uncompress_shared_libraries
} else {
uncompress_shared_libraries = true
}
# Android N+ better supports multiple locales (https://crbug.com/780847).
if (defined(invoker.support_zh_hk)) {
support_zh_hk = invoker.support_zh_hk
} else {
support_zh_hk = false
}
if (_is_bundle_module) {
_pak_prefix += "_bundle_module"
} else {
_pak_prefix += "_apk"
}
deps += [ "//chrome/android:${_pak_prefix}_pak_assets" ]
if (defined(invoker.negative_main_dex_globs)) {
negative_main_dex_globs = invoker.negative_main_dex_globs
} else if (_enable_multidex && invoker.target_type == "android_apk") {
# WebView pulls play services into the main dex.
negative_main_dex_globs = [
# TODO(agrieve): Add ApplicationStatus to this list. It's currently
# included because of ActivityWindowAndroid, but is never used at
# runtime by webview.
"*ChromeActivity*", # Pulls in the world, so ensure it doesn't slip
# in.
]
}
if (!is_java_debug) {
proguard_configs = []
if (defined(invoker.proguard_configs)) {
proguard_configs += invoker.proguard_configs
}
if (is_monochrome) {
proguard_configs +=
[ "//android_webview/nonembedded/java/proguard.flags" ]
}
}
}
# The _overrides scope is used to ensure that:
# * Values set in invoker cannot accidentally clobber values set in
# _overrides.
# * Values set in _overrides cannot accidentaly clobber values set in
# invoker (since the forward_variables_from will fail).
# Other nice properties:
# * _override_args needs to only reference values set within _overrides
# (as opposed to creating a list of values not set in it, which would be
# hard to keep up-to-date).
# * GN will issue an unused variable warning if there are entries missing
# from _override_args.
_override_args = [
"alternative_android_sdk_dep",
"app_as_shared_lib",
"deps",
"is_monochrome",
"is_trichrome",
"loadable_modules",
"native_lib_placeholders",
"negative_main_dex_globs",
"never_incremental",
"no_xml_namespaces",
"product_config_java_packages",
"proguard_configs",
"resources_config_path",
"secondary_abi_loadable_modules",
"secondary_abi_shared_libraries",
"secondary_native_lib_placeholders",
"shared_libraries",
"support_zh_hk",
"uncompress_shared_libraries",
"use_chromium_linker",
"use_modern_linker",
"webview_product_config_java_package",
]
forward_variables_from(invoker, "*", _override_args)
forward_variables_from(_overrides, _override_args)
}
}