| # 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" | |
| # Build Monochrome/Trichrome as a 64-bit browser. | |
| android_64bit_browser = false | |
| } | |
| default_chrome_public_jinja_variables = [ | |
| "channel=$android_channel", | |
| "enable_vr=$enable_vr", | |
| "include_arcore_manifest_flag=$package_arcore", | |
| ] | |
| if (android_64bit_browser) { | |
| current_abi_is_webview_only = | |
| defined(android_secondary_abi_toolchain) && | |
| current_toolchain == android_secondary_abi_toolchain | |
| } else { | |
| current_abi_is_webview_only = | |
| defined(android_secondary_abi_toolchain) && | |
| current_toolchain != android_secondary_abi_toolchain | |
| } | |
| # 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. | |
| # 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"). | |
| # is_modern: Optional. true iff this is a chrome_modern derived 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'") | |
| # 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 (!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 | |
| _use_trichrome_library = | |
| defined(invoker.use_trichrome_library) && invoker.use_trichrome_library | |
| assert(_use_trichrome_library || !_use_trichrome_library) # 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, "*") | |
| 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). | |
| 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)) { | |
| aapt_locale_whitelist = locales - android_chrome_omitted_locales | |
| } | |
| if (!_is_monochrome) { | |
| deps += [ | |
| "//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so", | |
| ] | |
| 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 { | |
| 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" ] | |
| } | |
| if (enable_vr && (_target_type == "android_apk" || !modularize_vr)) { | |
| deps += [ "//chrome/browser/android/vr:java" ] | |
| } | |
| if (!defined(version_code)) { | |
| if (_use_trichrome_library) { | |
| 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. | |
| 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_monochrome = true | |
| use_trichrome_library = | |
| defined(invoker.use_trichrome_library) && invoker.use_trichrome_library | |
| if (!use_trichrome_library) { | |
| 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 (android_64bit_browser) { | |
| shared_libraries = [ "//chrome/android:monochrome${_suffix}" ] | |
| if (build_apk_secondary_abi) { | |
| secondary_abi_shared_libraries = [ "//android_webview:monochrome${_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}" | |
| } | |
| } else { | |
| # Include a placeholder library to ensure that Chrome runs with | |
| # the correct bitness (same as the placeholder). | |
| if (android_64bit_target_cpu && !android_64bit_browser) { | |
| # We don't want to be 64-bit, only include a placeholder for secondary. | |
| secondary_native_lib_placeholders = [ "libdummy.so" ] | |
| } else { | |
| native_lib_placeholders = [ "libdummy.so" ] | |
| } | |
| } | |
| alternative_android_sdk_dep = webview_framework_dep | |
| app_as_shared_lib = true | |
| use_chromium_linker = false | |
| min_sdk_version = 24 | |
| # Webview supports all locales (has no omitted ones). | |
| aapt_locale_whitelist = locales | |
| # 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, "*") | |
| # Android N+ better supports multiple locales (https://crbug.com/780847). | |
| support_zh_hk = false | |
| if (!defined(deps)) { | |
| deps = [] | |
| } | |
| deps += [ | |
| "//android_webview:monochrome_webview_assets", | |
| "//android_webview/apk:webview_license_activity_java", | |
| "//android_webview/glue", | |
| "//chrome/android:chrome_public_non_pak_assets", | |
| "//chrome/android/monochrome:monochrome_license_provider_java", | |
| "//components/crash/android:handler_java", | |
| ] | |
| if (invoker.target_type == "android_app_bundle_module") { | |
| deps += | |
| [ "//chrome/android:monochrome_${bundle_pak_asset_type}_pak_assets" ] | |
| } else { | |
| deps += [ "//chrome/android:monochrome_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 = [] | |
| } | |
| proguard_configs += [ "//android_webview/apk/java/proguard.flags" ] | |
| png_to_webp = true | |
| } | |
| # TODO(crbug.com/862719): Remove Java VR code from the monochrome base | |
| # module once we can conditionally install the VR DFM. | |
| if (enable_vr) { | |
| deps += [ "//chrome/browser/android/vr:java" ] | |
| } | |
| if ((invoker.target_type == "android_apk" || !modularize_ar) && | |
| package_arcore) { | |
| deps += [ "//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" ] | |
| } | |
| } | |
| } | |
| } |