blob: cdbfd754ee333dad8a48c97f60f9e8389fc92921 [file] [log] [blame]
# Copyright 2018 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("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/util/version.gni")
import("//chrome/android/chrome_public_apk_tmpl.gni")
import("//chrome/android/modules/buildflags.gni")
if (!defined(default_trichrome_certdigest)) {
default_trichrome_certdigest =
"32a2fc74d731105859e5a85df16d95f102d85b22099b8064c5d8915c61dad1e0"
}
declare_args() {
# The package name for the Trichrome static shared library on Android.
trichrome_library_package = "org.chromium.trichromelibrary"
# The SHA256 certificate digest for the Trichrome static shared library on
# Android. You can use "apksigner verify --print-certs" on the signed APK to
# calculate the correct digest.
trichrome_certdigest = default_trichrome_certdigest
# WIP: Enable synchronized proguard for Trichrome. (http://crbug.com/901465)
# Only affects trichrome targets when !is_java_debug.
enable_trichrome_synchronized_proguard = false
}
trichrome_jinja_variables = [
"min_sdk_version=29",
"target_sdk_version=$android_sdk_version",
"trichrome_library=$trichrome_library_package",
"trichrome_certdigest=$trichrome_certdigest",
"use32bitAbi=android:use32bitAbi=\"true\"",
]
trichrome_synchronized_proguard =
enable_trichrome_synchronized_proguard && !is_java_debug
template("trichrome_library_apk_tmpl") {
android_apk(target_name) {
forward_variables_from(invoker,
[
"android_manifest",
"android_manifest_dep",
"apk_name",
"expected_android_manifest",
"expected_libs_and_assets",
"min_sdk_version",
"target_sdk_version",
])
# TODO(torne): since there's no real java code in the library right now,
# leave out the build hooks and let them get compiled into each APK. Later
# this should probably be in the library.
no_build_hooks = true
alternative_android_sdk_dep = webview_framework_dep
if (trichrome_synchronized_proguard) {
# TODO(crbug.com/956839): Remove this once R8 fixes the class merging
# and/or inlining bugs.
disable_r8_outlining = true
if (defined(invoker.webview_target) && defined(invoker.chrome_target)) {
shared_resources_allowlist_locales = locales
static_library_dependent_targets = [
{
name = invoker.webview_target
is_resource_ids_provider = true
},
{
name = invoker.chrome_target
is_resource_ids_provider = false
},
]
}
} else {
# TODO(crbug.com/901465): Remove r_java_root_package_name once shared
# Java code is moved to the shared library even in debug.
r_java_root_package_name = "trichrome_lib"
app_as_shared_lib = true
}
# No support for this has been added, also not supported by test runner
# since trichrome library is used in "additional_apks" in the trichrome
# bundle smoke tests.
never_incremental = true
uncompress_shared_libraries = true
uncompress_dex = true
version_name = chrome_version_name
if (android_64bit_target_cpu) {
if (invoker.is_64_bit_browser) {
if (invoker.include_32_bit_webview) {
version_code = trichrome_64_32_version_code
} else {
version_code = trichrome_64_version_code
}
} else {
if (invoker.include_64_bit_webview) {
version_code = trichrome_32_64_version_code
} else {
version_code = trichrome_32_version_code
}
}
} else {
version_code = trichrome_version_code
}
min_sdk_version = 29
if (trichrome_synchronized_proguard) {
product_version_resources_dep =
"//chrome/android:product_version_resources"
} else {
generate_buildconfig_java = false
}
# TODO(torne): using icon_resources just to get a temporary icon
deps = [
"//android_webview/nonembedded:icon_resources",
"//third_party/icu:icu_assets",
]
# 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) {
# Include the actual browser-bitness libmonochrome library, dependencies
# (crashpad and linker), and an opposite-bitness placeholder library to
# ensure that the library is treated as multiarch and gets its Java code
# precompiled for both architectures.
if (invoker.is_64_bit_browser) {
shared_libraries = [ "//chrome/android:libmonochrome_64" ]
_include_primary_support = true
if (invoker.include_32_bit_webview) {
secondary_native_lib_placeholders = [ "libdummy.so" ]
}
} else {
secondary_abi_shared_libraries =
[ "//chrome/android:monochrome_secondary_abi_lib" ]
_include_secondary_support = true
if (invoker.include_64_bit_webview) {
native_lib_placeholders = [ "libdummy.so" ]
}
}
} else {
shared_libraries = [ "//chrome/android:libmonochrome" ]
_include_primary_support = true
}
if (_include_primary_support) {
deps += [
"//chrome/android:chrome_public_v8_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:v8_snapshot_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" ]
}
# http://crbug.com/1042107.
if (is_component_build) {
main_component_library = "libmonochrome.cr.so"
}
if (!is_java_debug) {
proguard_enabled = true
proguard_configs = [
"//base/android/proguard/chromium_apk.flags",
"//base/android/proguard/chromium_code.flags",
"//chrome/android/proguard/trichrome.flags",
]
if (trichrome_synchronized_proguard) {
proguard_configs += [
"//chrome/android/proguard/static_library_dex_reference_workarounds.flags",
"//base/android/proguard/enable_obfuscation.flags",
]
} else {
# Disabling all obfuscation for the Trichrome library as a temporary
# workaround for crbug.com/1012842. There were naming conflicts between
# Library and Chrome, since each Proguard run doesn't know about the
# other, and thus handed out the first names (a, b, c) to both.
proguard_enable_obfuscation = false
}
}
deps += [ "//chrome/android:trichrome_dummy_resources" ]
}
}
# An .ssargs file is a text file to specify multiple input files with respective
# parameters, and is used by SuperSize-archive to create multi-container .size
# files. This is used to support SuperSize on Trichrome.
template("write_ssargs_trichrome") {
if (target_cpu == "arm64" || target_cpu == "x64") {
# Ignore secondary abi libmonochrome in library apk in favor of primary one
# in TrichromeWebView.
_library_args = " --no-native"
} else {
_library_args = ""
}
# Base names (i.e., no full path) are used because .ssargs files specifies
# files using paths relative to itself. It is expected for |ssargs_path| to
# be in the same directory as all Trichrome files whose sizes are measured
# by SuperSize.
_lines = [
"# Written by build target \"${target_name}.\"",
"Library -f ${invoker.trichrome_library_basename}$_library_args",
"# Add --no-native to Chrome as workaround for crbug.com/1103271.",
"Chrome -f ${invoker.trichrome_chrome_basename} --no-native",
"WebView -f ${invoker.trichrome_webview_basename}",
]
write_file(invoker.ssargs_path, _lines)
}