| # 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/resource_exclusions.gni") |
| import("//build/config/android/abi.gni") |
| import("//build/config/android/config.gni") |
| import("//build/config/android/rules.gni") |
| import("//build/config/locales.gni") |
| import("//build/util/version.gni") |
| import("//chrome/android/trichrome.gni") |
| import("//device/vr/buildflags/buildflags.gni") |
| import("//tools/v8_context_snapshot/v8_context_snapshot.gni") |
| import("//weblayer/variables.gni") |
| import("//weblayer/weblayer_resource_exclusions.gni") |
| |
| declare_args() { |
| # Android package name to use when compiling the system_webview_apk and |
| # trichrome_webview_apk targets. This should be used if the Android build |
| # on which you are going to install WebView is configured to load a |
| # different package name than the default used in AOSP. |
| system_webview_package_name = "com.android.webview" |
| |
| # Whether to enable standalone and trichrome WebView bundle build targets. |
| enable_webview_bundles = true |
| } |
| |
| template("system_webview_apk_or_module_tmpl") { |
| if (!defined(invoker.target_type)) { |
| _is_bundle_module = false |
| _target_type = "android_apk" |
| } else { |
| _is_bundle_module = invoker.target_type == "android_app_bundle_module" |
| _target_type = invoker.target_type |
| } |
| _exclude_weblayer_java = |
| defined(invoker.exclude_weblayer_java) && invoker.exclude_weblayer_java |
| target(_target_type, target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "is_64_bit_browser", |
| "include_32_bit_webview", |
| "include_64_bit_webview", |
| ]) |
| |
| deps += [ |
| "//android_webview:locale_pak_assets", |
| "//android_webview:pak_file_assets", |
| ] |
| |
| if (_exclude_weblayer_java) { |
| deps += [ "//android_webview:android_webview_no_weblayer_java" ] |
| } else { |
| if (_is_bundle_module && weblayer_in_split && webview_includes_weblayer) { |
| deps += [ |
| # TODO(crbug.com/1105096): WebLayer resources are added to the base |
| # module for now because of bugs with shared resources in splits. |
| ":${target_name}__all_weblayer_resources", |
| "//android_webview:android_webview_no_weblayer_java", |
| "//weblayer/browser/java:base_module_java", |
| ] |
| if (defined(invoker.expected_android_manifest)) { |
| _bundle_target_gen_dir = |
| get_label_info(invoker.bundle_target, "target_gen_dir") |
| _bundle_name = get_label_info(invoker.bundle_target, "name") |
| extra_verification_manifest = "${_bundle_target_gen_dir}/${_bundle_name}__weblayer_bundle_module_manifest/AndroidManifest.xml" |
| extra_verification_manifest_dep = "${invoker.bundle_target}__weblayer_bundle_module__merge_manifests" |
| } |
| } else { |
| deps += [ "//android_webview:android_webview_java" ] |
| } |
| |
| # Resources from this target will be kept in the base bundle module |
| # instead of in language splits. |
| if (!defined(invoker.shared_resources_allowlist_target)) { |
| shared_resources_allowlist_target = |
| "//android_webview:system_webview_no_weblayer_apk" |
| } |
| } |
| |
| product_config_java_packages = [ webview_product_config_java_package ] |
| |
| if (webview_includes_weblayer) { |
| if (_is_bundle_module) { |
| deps += [ "//weblayer:bundle_locale_pak_assets" ] |
| } else { |
| deps += [ "//weblayer:locale_pak_assets" ] |
| } |
| product_config_java_packages += [ weblayer_product_config_java_package ] |
| } |
| |
| if (!defined(alternative_android_sdk_dep)) { |
| alternative_android_sdk_dep = webview_framework_dep |
| } |
| |
| if (webview_devui_show_icon) { |
| deps += [ "//android_webview/nonembedded:devui_launcher_icon_resources" ] |
| } |
| |
| _use_trichrome_library = |
| defined(use_trichrome_library) && use_trichrome_library |
| assert( |
| _use_trichrome_library == 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.") |
| |
| # Pure 32-bit implies a 32-bit only Webview built on a 64-bit configuration. |
| _pure_32_bit = |
| android_64bit_target_cpu && defined(invoker.include_64_bit_webview) && |
| !invoker.include_64_bit_webview |
| _pure_64_bit = |
| android_64bit_target_cpu && defined(invoker.include_32_bit_webview) && |
| !invoker.include_32_bit_webview |
| not_needed([ |
| "_pure_32_bit", |
| "_pure_64_bit", |
| ]) |
| |
| # Flag whether additional deps and libs should be included for each ABI. |
| _include_primary_support = false |
| _include_secondary_support = false |
| |
| if (!_use_trichrome_library) { |
| shared_resources = true |
| |
| if (!android_64bit_target_cpu || !_pure_32_bit) { |
| shared_libraries = [ "//android_webview:libwebviewchromium" ] |
| _include_primary_support = true |
| } |
| if (android_64bit_target_cpu && !_pure_64_bit) { |
| secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ] |
| _include_secondary_support = true |
| } |
| deps += [ "//third_party/icu:icu_assets" ] |
| } else { |
| uncompress_shared_libraries = true |
| app_as_shared_lib = true |
| |
| # Include placeholder libraries to ensure we are treated as the desired |
| # architecture. |
| if (android_64bit_target_cpu) { |
| if (invoker.is_64_bit_browser) { |
| native_lib_placeholders = [ "libdummy.so" ] |
| if (invoker.include_32_bit_webview) { |
| secondary_abi_shared_libraries = [ "//android_webview:monochrome_64($android_secondary_abi_toolchain)" ] |
| _include_secondary_support = true |
| } |
| } else { |
| if (invoker.include_64_bit_webview) { |
| shared_libraries = [ "//android_webview:monochrome" ] |
| _include_primary_support = true |
| } |
| secondary_native_lib_placeholders = [ "libdummy.so" ] |
| } |
| } else { |
| native_lib_placeholders = [ "libdummy.so" ] |
| } |
| } |
| |
| _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" |
| not_needed([ "_libarcore_dir" ]) |
| |
| _include_arcore = |
| webview_includes_weblayer && enable_arcore && !_exclude_weblayer_java && |
| (_include_secondary_support || _include_primary_support) |
| |
| if (_include_primary_support) { |
| deps += [ |
| "//android_webview:webview_primary_abi_assets", |
| "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline", |
| ] |
| loadable_modules = [ "$root_out_dir/libcrashpad_handler_trampoline.so" ] |
| if (webview_includes_weblayer) { |
| deps += [ "//base/android/linker:chromium_android_linker" ] |
| loadable_modules += |
| [ "$root_out_dir/libchromium_android_linker$shlib_extension" ] |
| } |
| if (_include_arcore) { |
| loadable_modules += |
| [ "$_libarcore_dir/$android_app_abi/libarcore_sdk_c.so" ] |
| } |
| } |
| if (_include_secondary_support) { |
| _trampoline = "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline($android_secondary_abi_toolchain)" |
| deps += [ |
| "//android_webview: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 (webview_includes_weblayer) { |
| deps += [ "//base/android/linker:chromium_android_linker($android_secondary_abi_toolchain)" ] |
| secondary_abi_loadable_modules += |
| [ "$_secondary_out_dir/libchromium_android_linker$shlib_extension" ] |
| } |
| if (_include_arcore) { |
| secondary_abi_loadable_modules += |
| [ "$_libarcore_dir/$android_app_secondary_abi/libarcore_sdk_c.so" ] |
| } |
| } |
| |
| if (_include_arcore) { |
| deps += [ "//third_party/arcore-android-sdk-client:com_google_ar_core_J__unpack_aar" ] |
| } |
| |
| aapt_locale_allowlist = platform_pak_locales |
| |
| resource_exclusion_regex = common_resource_exclusion_regex |
| resource_exclusion_exceptions = common_resource_exclusion_exceptions |
| |
| if (webview_includes_weblayer) { |
| resource_values_filter_rules = weblayer_resource_values_filter_rules |
| resource_exclusion_exceptions += weblayer_resource_exclusion_exceptions |
| |
| # Note: WebLayer's resource exclusion regex deliberately does not start |
| # with "|". |
| resource_exclusion_regex += "|" + weblayer_resource_exclusion_regex |
| } |
| |
| # We only optimize resources for bundles since APKs are not shipped. |
| # Resources only live in the base module atm as such we only need to set |
| # these on the base module |
| if (_is_bundle_module) { |
| # Removes metadata needed for Resources.getIdentifier("resource_name"). |
| strip_resource_names = !is_java_debug |
| |
| # Shortens resource file names in apk eg: res/drawable/button.xml -> res/a.xml |
| short_resource_paths = !is_java_debug |
| |
| # Removes unused resources from the apk. Only enabled on official builds |
| # since it adds a slow step and serializes the build graph causing fewer |
| # expensive tasks (eg: proguarding, resource optimization) to be run in |
| # parallel by adding dependencies between them (adds around 10-20 |
| # seconds on my machine). |
| strip_unused_resources = is_official_build |
| } |
| |
| if (!_is_bundle_module) { |
| # Used as an additional apk in test scripts. |
| never_incremental = true |
| command_line_flags_file = "webview-command-line" |
| } |
| |
| if (!is_java_debug) { |
| proguard_enabled = true |
| if (!defined(proguard_configs)) { |
| proguard_configs = [] |
| } |
| proguard_configs += [ |
| "//android_webview/nonembedded/java/proguard.flags", |
| "//base/android/proguard/chromium_apk.flags", |
| "//base/android/proguard/chromium_code.flags", |
| ] |
| png_to_webp = true |
| } |
| |
| if (!defined(version_code)) { |
| if (_use_trichrome_library) { |
| 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 |
| } |
| } else { |
| if (android_channel == "dev") { |
| if (_pure_32_bit) { |
| version_code = webview_32_dev_version_code |
| } else if (_pure_64_bit) { |
| version_code = webview_64_dev_version_code |
| } else { |
| version_code = webview_dev_version_code |
| } |
| } else if (android_channel == "beta") { |
| if (_pure_32_bit) { |
| version_code = webview_32_beta_version_code |
| } else if (_pure_64_bit) { |
| version_code = webview_64_beta_version_code |
| } else { |
| version_code = webview_beta_version_code |
| } |
| } else { |
| if (_pure_32_bit) { |
| version_code = webview_32_stable_version_code |
| } else if (_pure_64_bit) { |
| version_code = webview_64_stable_version_code |
| } else { |
| version_code = webview_stable_version_code |
| } |
| } |
| } |
| } |
| if (!defined(version_name)) { |
| version_name = chrome_version_name |
| } |
| } |
| } |