system_webview_apk_tmpl.gni 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. # Copyright 2015 The Chromium Authors
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//android_webview/variables.gni")
  5. import("//base/android/resource_exclusions.gni")
  6. import("//build/config/android/abi.gni")
  7. import("//build/config/android/config.gni")
  8. import("//build/config/android/rules.gni")
  9. import("//build/config/locales.gni")
  10. import("//chrome/android/trichrome.gni")
  11. import("//chrome/version.gni")
  12. import("//components/crash/android/silent_java_assert_reporting.gni")
  13. import("//device/vr/buildflags/buildflags.gni")
  14. import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
  15. import("//weblayer/variables.gni")
  16. import("//weblayer/weblayer_resource_exclusions.gni")
  17. declare_args() {
  18. # Android package name to use when compiling the system_webview_apk and
  19. # trichrome_webview_apk targets. This should be used if the Android build
  20. # on which you are going to install WebView is configured to load a
  21. # different package name than the default used in AOSP.
  22. system_webview_package_name = "com.android.webview"
  23. # Whether to enable standalone and trichrome WebView bundle build targets.
  24. enable_webview_bundles = true
  25. }
  26. template("system_webview_apk_or_module_tmpl") {
  27. if (!defined(invoker.target_type)) {
  28. _is_bundle_module = false
  29. _target_type = "android_apk"
  30. } else {
  31. _is_bundle_module = invoker.target_type == "android_app_bundle_module"
  32. _target_type = invoker.target_type
  33. }
  34. _exclude_weblayer_java =
  35. defined(invoker.exclude_weblayer_java) && invoker.exclude_weblayer_java
  36. target(_target_type, target_name) {
  37. forward_variables_from(invoker,
  38. "*",
  39. [
  40. "is_64_bit_browser",
  41. "include_32_bit_webview",
  42. "include_64_bit_webview",
  43. ])
  44. _omit_dex = defined(omit_dex) && omit_dex
  45. deps += [
  46. "//android_webview:locale_pak_assets",
  47. "//android_webview:pak_file_assets",
  48. ]
  49. if (_exclude_weblayer_java) {
  50. deps += [ "//android_webview:android_webview_no_weblayer_java" ]
  51. } else {
  52. if (_is_bundle_module && weblayer_in_split && webview_includes_weblayer) {
  53. deps += [
  54. # TODO(crbug.com/1105096): WebLayer resources are added to the base
  55. # module for now because of bugs with shared resources in splits.
  56. ":${target_name}__all_weblayer_resources",
  57. "//android_webview:android_webview_no_weblayer_java",
  58. "//weblayer/browser/java:base_module_java",
  59. ]
  60. if (defined(invoker.expected_android_manifest)) {
  61. _bundle_target_gen_dir =
  62. get_label_info(invoker.bundle_target, "target_gen_dir")
  63. _bundle_name = get_label_info(invoker.bundle_target, "name")
  64. extra_verification_manifest = "${_bundle_target_gen_dir}/${_bundle_name}__weblayer_bundle_module/AndroidManifest.merged.xml"
  65. extra_verification_manifest_dep = "${invoker.bundle_target}__weblayer_bundle_module__merge_manifests"
  66. }
  67. } else {
  68. deps += [ "//android_webview:android_webview_java" ]
  69. }
  70. # Resources from this target will be kept in the base bundle module
  71. # instead of in language splits.
  72. if (!defined(invoker.shared_resources_allowlist_target)) {
  73. shared_resources_allowlist_target =
  74. "//android_webview:system_webview_no_weblayer_apk"
  75. }
  76. }
  77. if (!_omit_dex) {
  78. product_config_java_packages = [ webview_product_config_java_package ]
  79. }
  80. if (webview_includes_weblayer) {
  81. if (_is_bundle_module) {
  82. deps += [ "//weblayer:bundle_locale_pak_assets" ]
  83. } else {
  84. deps += [ "//weblayer:locale_pak_assets" ]
  85. }
  86. if (!_omit_dex) {
  87. product_config_java_packages += [ weblayer_product_config_java_package ]
  88. }
  89. }
  90. if (!defined(alternative_android_sdk_dep)) {
  91. alternative_android_sdk_dep = webview_framework_dep
  92. }
  93. if (webview_devui_show_icon) {
  94. deps += [ "//android_webview/nonembedded:devui_launcher_icon_resources" ]
  95. }
  96. _use_trichrome_library =
  97. defined(use_trichrome_library) && use_trichrome_library
  98. assert(
  99. _use_trichrome_library == defined(invoker.static_library_provider),
  100. "If trichrome library is used, static_library_provider must be set " +
  101. "so that a dep can be added on the library APK.")
  102. _include_32_bit_webview = !defined(invoker.include_32_bit_webview) ||
  103. invoker.include_32_bit_webview
  104. if (android_64bit_target_cpu) {
  105. _include_64_bit_webview = !defined(invoker.include_64_bit_webview) ||
  106. invoker.include_64_bit_webview
  107. }
  108. # Pure 32-bit implies a 32-bit only Webview built on a 64-bit configuration.
  109. _pure_32_bit = android_64bit_target_cpu && !_include_64_bit_webview
  110. _pure_64_bit = android_64bit_target_cpu && !_include_32_bit_webview
  111. not_needed([
  112. "_include_32_bit_webview",
  113. "_pure_32_bit",
  114. "_pure_64_bit",
  115. ])
  116. # Flag whether additional deps and libs should be included for each ABI.
  117. _include_primary_support = false
  118. _include_secondary_support = false
  119. if (!_use_trichrome_library) {
  120. shared_resources = true
  121. if ((!android_64bit_target_cpu && _include_32_bit_webview) ||
  122. (android_64bit_target_cpu && !_pure_32_bit)) {
  123. shared_libraries = [ "//android_webview:libwebviewchromium" ]
  124. _include_primary_support = true
  125. }
  126. if (android_64bit_target_cpu && !_pure_64_bit) {
  127. secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ]
  128. _include_secondary_support = true
  129. }
  130. deps += [ "//third_party/icu:icu_assets" ]
  131. } else {
  132. uncompress_shared_libraries = true
  133. app_as_shared_lib = true
  134. # Include placeholder libraries to ensure we are treated as the desired
  135. # architecture.
  136. if (android_64bit_target_cpu) {
  137. if (invoker.is_64_bit_browser) {
  138. native_lib_placeholders = [ "libdummy.so" ]
  139. if (_include_32_bit_webview) {
  140. secondary_abi_shared_libraries = [ "//android_webview:monochrome_64($android_secondary_abi_toolchain)" ]
  141. _include_secondary_support = true
  142. }
  143. } else {
  144. if (_include_64_bit_webview) {
  145. shared_libraries = [ "//android_webview:monochrome" ]
  146. _include_primary_support = true
  147. }
  148. secondary_native_lib_placeholders = [ "libdummy.so" ]
  149. static_library_provider_use_secondary_abi = true
  150. }
  151. # http://crbug.com/1042107.
  152. if (is_component_build) {
  153. if (invoker.is_64_bit_browser) {
  154. main_component_library = "libmonochrome_64.cr.so"
  155. } else {
  156. main_component_library = "libmonochrome.cr.so"
  157. }
  158. }
  159. } else {
  160. native_lib_placeholders = [ "libdummy.so" ]
  161. }
  162. }
  163. _libarcore_dir = get_label_info(
  164. "//third_party/arcore-android-sdk-client:com_google_ar_core_java($default_toolchain)",
  165. "target_out_dir") + "/com_google_ar_core_java/jni"
  166. not_needed([ "_libarcore_dir" ])
  167. _include_arcore =
  168. webview_includes_weblayer && enable_arcore && !_exclude_weblayer_java &&
  169. (_include_secondary_support || _include_primary_support)
  170. if (_include_primary_support) {
  171. deps += [
  172. "//android_webview:webview_primary_abi_assets",
  173. "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline",
  174. ]
  175. loadable_modules = [ "$root_out_dir/libcrashpad_handler_trampoline.so" ]
  176. if (webview_includes_weblayer) {
  177. deps += [ "//base/android/linker:chromium_android_linker" ]
  178. loadable_modules +=
  179. [ "$root_out_dir/libchromium_android_linker$shlib_extension" ]
  180. }
  181. if (_include_arcore) {
  182. loadable_modules +=
  183. [ "$_libarcore_dir/$android_app_abi/libarcore_sdk_c.so" ]
  184. }
  185. }
  186. if (_include_secondary_support) {
  187. _trampoline = "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline($android_secondary_abi_toolchain)"
  188. deps += [
  189. "//android_webview:webview_secondary_abi_assets",
  190. _trampoline,
  191. ]
  192. _secondary_out_dir = get_label_info(_trampoline, "root_out_dir")
  193. secondary_abi_loadable_modules =
  194. [ "$_secondary_out_dir/libcrashpad_handler_trampoline.so" ]
  195. if (webview_includes_weblayer) {
  196. deps += [ "//base/android/linker:chromium_android_linker($android_secondary_abi_toolchain)" ]
  197. secondary_abi_loadable_modules +=
  198. [ "$_secondary_out_dir/libchromium_android_linker$shlib_extension" ]
  199. }
  200. if (_include_arcore) {
  201. secondary_abi_loadable_modules +=
  202. [ "$_libarcore_dir/$android_app_secondary_abi/libarcore_sdk_c.so" ]
  203. }
  204. }
  205. if (_include_arcore) {
  206. deps += [ "//third_party/arcore-android-sdk-client:com_google_ar_core_J__unpack_aar" ]
  207. }
  208. aapt_locale_allowlist = platform_pak_locales
  209. resource_exclusion_regex = common_resource_exclusion_regex
  210. resource_exclusion_exceptions = common_resource_exclusion_exceptions
  211. if (webview_includes_weblayer) {
  212. resource_values_filter_rules = weblayer_resource_values_filter_rules
  213. resource_exclusion_exceptions += weblayer_resource_exclusion_exceptions
  214. # Note: WebLayer's resource exclusion regex deliberately does not start
  215. # with "|".
  216. resource_exclusion_regex += "|" + weblayer_resource_exclusion_regex
  217. }
  218. # We only optimize resources for bundles since APKs are not shipped.
  219. # Resources only live in the base module atm as such we only need to set
  220. # these on the base module
  221. if (_is_bundle_module) {
  222. # Removes metadata needed for Resources.getIdentifier("resource_name").
  223. strip_resource_names = !is_java_debug
  224. # Shortens resource file names in apk eg: res/drawable/button.xml -> res/a.xml
  225. short_resource_paths = !is_java_debug
  226. # Removes unused resources from the apk. Only enabled on official builds
  227. # since it adds a slow step and serializes the build graph causing fewer
  228. # expensive tasks (eg: proguarding, resource optimization) to be run in
  229. # parallel by adding dependencies between them (adds around 10-20
  230. # seconds on my machine).
  231. strip_unused_resources = is_official_build
  232. }
  233. if (!_is_bundle_module) {
  234. # Used as an additional apk in test scripts.
  235. never_incremental = true
  236. command_line_flags_file = "webview-command-line"
  237. }
  238. if (!is_java_debug && !_omit_dex) {
  239. proguard_enabled = true
  240. if (!defined(proguard_configs)) {
  241. proguard_configs = []
  242. }
  243. proguard_configs +=
  244. [ "//android_webview/nonembedded/java/proguard.flags" ]
  245. png_to_webp = true
  246. }
  247. if (enable_silent_java_assert_reporting && !_omit_dex) {
  248. custom_assertion_handler = crash_reporting_assertion_handler
  249. }
  250. if (!defined(version_code)) {
  251. if (_use_trichrome_library) {
  252. if (android_64bit_target_cpu) {
  253. if (invoker.is_64_bit_browser) {
  254. if (_include_32_bit_webview) {
  255. version_code = trichrome_64_32_version_code
  256. } else {
  257. version_code = trichrome_64_version_code
  258. }
  259. } else {
  260. if (_include_64_bit_webview) {
  261. version_code = trichrome_32_64_version_code
  262. } else {
  263. version_code = trichrome_32_version_code
  264. }
  265. }
  266. } else {
  267. version_code = trichrome_version_code
  268. }
  269. } else {
  270. if (android_channel == "dev") {
  271. if (_pure_32_bit) {
  272. version_code = webview_32_dev_version_code
  273. } else if (_pure_64_bit) {
  274. version_code = webview_64_dev_version_code
  275. } else {
  276. version_code = webview_dev_version_code
  277. }
  278. } else if (android_channel == "beta") {
  279. if (_pure_32_bit) {
  280. version_code = webview_32_beta_version_code
  281. } else if (_pure_64_bit) {
  282. version_code = webview_64_beta_version_code
  283. } else {
  284. version_code = webview_beta_version_code
  285. }
  286. } else {
  287. if (_pure_32_bit) {
  288. version_code = webview_32_stable_version_code
  289. } else if (_pure_64_bit) {
  290. version_code = webview_64_stable_version_code
  291. } else {
  292. version_code = webview_stable_version_code
  293. }
  294. }
  295. }
  296. }
  297. if (!defined(version_name)) {
  298. version_name = chrome_version_name
  299. }
  300. }
  301. }