blob: eb3ec3ff71fdac3f8944320c065a1fad9851fd2d [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("//base/android/linker/config.gni")
import("//base/android/proguard/proguard.gni")
import("//build/config/android/chrome_version.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("//chrome/android/chrome_common_shared_library.gni")
import("//chrome/common/features.gni")
import("//device/vr/buildflags/buildflags.gni")
import("channel.gni")
declare_args() {
# Enable multidex in release builds.
multidex_in_release = false
# Experimental only. Causes .dex files to be store in the APK uncompressed.
# Only affects monochrome_public_apk and trichrome_chrome_apk.
use_uncompressed_dex = false
# Enable language splits in the Chrome bundles.
enable_chrome_language_splits = android_channel == "default"
}
default_chrome_public_jinja_variables = [
"channel=$android_channel",
"enable_vr=$enable_vr",
"include_arcore_manifest_flag=$package_arcore",
"notouch_build=$notouch_build",
]
# 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.
# module_name: For bundle module target types, the module's 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(defined(invoker.target_type), "target_type is required!")
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'")
assert(!(defined(invoker.is_trichrome) && invoker.is_trichrome) ||
!(defined(invoker.is_monochrome) && invoker.is_monochrome),
"Cannot be both trichrome and monochrome!")
# 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) &&
invoker.add_unwind_tables_in_apk) {
_unwind_asset = "${target_name}_unwind_assets"
unwind_table_asset(_unwind_asset) {
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
library_target = invoker.shared_library_for_unwind_asset
deps = invoker.shared_libraries
if (build_apk_secondary_abi && defined(android_secondary_abi_cpu)) {
deps += [ "//chrome/android:${library_target}($android_secondary_abi_toolchain)" ]
}
}
}
if (!defined(invoker.target_type)) {
_target_type = "android_apk"
} else {
_target_type = invoker.target_type
}
_is_modern = defined(invoker.is_modern) && invoker.is_modern
assert(_is_modern || !_is_modern) # Mark as used.
_is_monochrome = defined(invoker.is_monochrome) && invoker.is_monochrome
_is_trichrome = defined(invoker.is_trichrome) && invoker.is_trichrome
assert(_is_trichrome || !_is_trichrome) # Mark as used.
if (defined(invoker.enable_multidex)) {
_enable_multidex = invoker.enable_multidex
} else {
_enable_multidex = is_java_debug || multidex_in_release
}
target(_target_type, target_name) {
forward_variables_from(invoker, "*")
if (_is_trichrome) {
min_sdk_version = 28
} else if (_is_monochrome) {
min_sdk_version = 24
} else if (_is_modern) {
min_sdk_version = 21
} else {
min_sdk_version = 19
}
resource_blacklist_regex = "[/-]xxxhdpi[/-]"
# Exception rationale in https://crbug.com/691733.
resource_blacklist_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.
]
# Use zh-TW strings for zh-HK (https://crbug.com/780847).
if (!defined(support_zh_hk)) {
support_zh_hk = true
}
optimize_resources = true
if (defined(shared_libraries) && 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_whitelist)) {
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_whitelist = locales - android_chrome_omitted_locales
} else {
# For bundles, only include resource strings files from our full
# locale list, but nothing more.
aapt_locale_whitelist = locales
}
}
if (!_is_monochrome && !_is_trichrome) {
deps += [
"//chrome/android:chrome_public_v8_assets",
"//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so",
"//third_party/icu:icu_assets",
]
if (!defined(loadable_modules)) {
loadable_modules = []
}
loadable_modules += [ "$root_out_dir/libcrashpad_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, so ensure it doesn't slip in.
"*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
}
}
}
# Only bundles can install modules. Therefore, include stub implementation
# for all other targets to save some binary size.
if (_target_type == "android_app_bundle_module") {
deps +=
[ "//components/module_installer/android:module_installer_impl_java" ]
} else if (_target_type == "instrumentation_test_apk") {
deps +=
[ "//components/module_installer/android:module_installer_test_java" ]
} else {
deps +=
[ "//components/module_installer/android:module_installer_stub_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"
} else {
deps += [ "//chrome/android:bundle_canary_java" ]
}
product_version_resources_dep = "//chrome/android:product_version_resources"
if (defined(invoker.add_unwind_tables_in_apk) &&
invoker.add_unwind_tables_in_apk) {
deps += [ ":$_unwind_asset" ]
}
deps += [ "//chrome/android:chrome_all_java" ]
if (enable_vr && (_target_type == "android_apk" || !modularize_vr)) {
deps += [ "//chrome/android/features/vr:java" ]
}
if (_target_type == "android_apk") {
deps += [ "//chrome/android/features/tab_ui: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") {
if (defined(invoker.enable_multidex)) {
_enable_multidex = invoker.enable_multidex
} else {
_enable_multidex = is_java_debug || multidex_in_release
}
chrome_public_common_apk_or_module_tmpl(target_name) {
is_trichrome =
defined(invoker.use_trichrome_library) && invoker.use_trichrome_library
is_monochrome = !is_trichrome
loadable_modules = []
secondary_abi_loadable_modules = []
_deps = [
"//components/crash/android:handler_java",
"//chrome/android:chrome_public_non_pak_assets",
]
if (is_monochrome) {
if (invoker.target_type == "android_app_bundle_module") {
_suffix = bundle_library_suffix
} else {
_suffix = ""
}
if (android_64bit_target_cpu) {
# Build //android_webview:monochrome with the opposite bitness that
# Chrome runs in.
if (defined(invoker.is_64_bit_browser) && invoker.is_64_bit_browser) {
shared_libraries = [ "//chrome/android:monochrome_64${_suffix}" ]
if (build_apk_secondary_abi && invoker.include_32_bit_webview) {
secondary_abi_shared_libraries = [ "//android_webview:monochrome_64${_suffix}($android_secondary_abi_toolchain)" ]
}
} else {
shared_libraries = [ "//android_webview:monochrome${_suffix}" ]
if (build_apk_secondary_abi) {
secondary_abi_shared_libraries =
[ "//chrome/android:monochrome${_suffix}_secondary_abi_lib" ]
}
}
} else {
shared_libraries = [ "//chrome/android:monochrome${_suffix}" ]
}
if (invoker.add_unwind_tables_in_apk) {
shared_library_for_unwind_asset = "monochrome${_suffix}"
}
_deps += [
"//android_webview:monochrome_webview_assets",
"//android_webview/apk:webview_license_activity_java",
"//android_webview/glue",
"//chrome/android:monochrome_java",
"//chrome/android/monochrome:monochrome_license_provider_java",
"//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline",
]
loadable_modules += [ "$root_out_dir/libcrashpad_handler_trampoline.so" ]
if (android_64bit_target_cpu && build_apk_secondary_abi &&
(!defined(invoker.is_64_bit_browser) || !invoker.is_64_bit_browser ||
invoker.include_32_bit_webview)) {
_trampoline = "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline($android_secondary_abi_toolchain)"
_deps += [ _trampoline ]
_secondary_out_dir = get_label_info(_trampoline, "root_out_dir")
secondary_abi_loadable_modules +=
[ "$_secondary_out_dir/libcrashpad_handler_trampoline.so" ]
}
alternative_android_sdk_dep = webview_framework_dep
app_as_shared_lib = true
_pak_prefix = "monochrome"
}
if (is_trichrome) {
if (!trichrome_shared_assets) {
_deps += [ "//android_webview:monochrome_webview_assets" ]
}
# 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.
native_lib_placeholders = [ "libdummy.so" ]
if (android_64bit_target_cpu && build_apk_secondary_abi) {
secondary_native_lib_placeholders = [ "libdummy.so" ]
}
_pak_prefix = "trichrome_chrome"
}
use_chromium_linker = false
# Resources config for blocklisting resource names from obfuscation
resources_config_path = "//android_webview/aapt2.config"
if (!defined(invoker.target_type) || invoker.target_type == "android_apk") {
# Incremental install doesn't work for monochrome. See crbug.com/663492.
never_incremental = true
uncompress_dex = use_uncompressed_dex
}
# 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.
no_xml_namespaces = true
# Configrations to make android load shared library from APK.
uncompress_shared_libraries = true
forward_variables_from(invoker, "*", [ "include_32_bit_webview" ])
# Android N+ better supports multiple locales (https://crbug.com/780847).
support_zh_hk = false
if (invoker.target_type == "android_app_bundle_module") {
_deps += [
"//chrome/android:${_pak_prefix}_${bundle_pak_asset_type}_pak_assets",
]
} else {
_deps += [ "//chrome/android:${_pak_prefix}_apk_pak_assets" ]
}
if (_enable_multidex && invoker.target_type == "android_apk" &&
!defined(invoker.negative_main_dex_globs)) {
# 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) {
if (!defined(proguard_configs)) {
proguard_configs = []
}
if (is_monochrome) {
proguard_configs += [ "//android_webview/apk/java/proguard.flags" ]
}
png_to_webp = true
}
if ((invoker.target_type == "android_apk" || !modularize_ar) &&
package_arcore) {
_deps += [
"//chrome/browser/android/vr:ar_java",
"//third_party/android_deps:com_google_ar_core_java",
]
# We store this as a separate .so in the APK and only load as needed.
if (android_64bit_target_cpu && build_apk_secondary_abi) {
secondary_abi_loadable_modules += [ "$root_gen_dir/third_party/android_deps/com_google_ar_core_java/jni/armeabi-v7a/libarcore_sdk_c.so" ]
} else if (android_64bit_target_cpu && !build_apk_secondary_abi) {
loadable_modules += [ "$root_gen_dir/third_party/android_deps/com_google_ar_core_java/jni/armeabi-v7a/libarcore_sdk_c.so" ]
} else {
loadable_modules += [ "$root_gen_dir/third_party/android_deps/com_google_ar_core_java/jni/armeabi-v7a/libarcore_sdk_c.so" ]
}
}
if (!defined(deps)) {
deps = []
}
deps += _deps
}
}