1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # This file is meant to be included into a target to provide a rule
6 # to build Android APKs in a consistent manner.
8 # To use this, create a gyp target with the following form:
10 # 'target_name': 'my_package_apk',
13 # 'apk_name': 'MyPackage',
14 # 'java_in_dir': 'path/to/package/root',
15 # 'resource_dir': 'path/to/package/root/res',
17 # 'includes': ['path/to/this/gypi/file'],
21 # apk_name - The final apk will be named <apk_name>.apk
22 # java_in_dir - The top-level java directory. The src should be in
24 # Optional/automatic variables:
25 # additional_input_paths - These paths will be included in the 'inputs' list to
26 # ensure that this target is rebuilt when one of these paths changes.
27 # additional_res_dirs - Additional directories containing Android resources.
28 # additional_res_packages - Package names of the R.java files corresponding to
29 # each directory in additional_res_dirs.
30 # additional_src_dirs - Additional directories with .java files to be compiled
31 # and included in the output of this target.
32 # asset_location - The directory where assets are located.
33 # generated_src_dirs - Same as additional_src_dirs except used for .java files
34 # that are generated at build time. This should be set automatically by a
35 # target's dependencies. The .java files in these directories are not
36 # included in the 'inputs' list (unlike additional_src_dirs).
37 # input_jars_paths - The path to jars to be included in the classpath. This
38 # should be filled automatically by depending on the appropriate targets.
39 # is_test_apk - Set to 1 if building a test apk. This prevents resources from
40 # dependencies from being re-included.
41 # native_lib_target - The target_name of the target which generates the final
42 # shared library to be included in this apk. A stripped copy of the
43 # library will be included in the apk.
44 # resource_dir - The directory for resources.
45 # R_package - A custom Java package to generate the resource file R.java in.
46 # By default, the package given in AndroidManifest.xml will be used.
47 # java_strings_grd - The name of the grd file from which to generate localized
48 # strings.xml files, if any.
49 # library_manifest_paths'- Paths to additional AndroidManifest.xml files from
54 'additional_input_paths': [],
55 'input_jars_paths': [],
56 'library_dexed_jars_paths': [],
57 'additional_src_dirs': [],
58 'generated_src_dirs': [],
59 'app_manifest_version_name%': '<(android_app_version_name)',
60 'app_manifest_version_code%': '<(android_app_version_code)',
61 'proguard_enabled%': 'false',
62 'proguard_flags_paths%': ['<(DEPTH)/build/android/empty_proguard.flags'],
63 'jar_name': 'chromium_apk_<(_target_name).jar',
64 'resource_dir%':'<(DEPTH)/build/android/ant/empty/res',
66 'additional_R_text_files': [],
67 'additional_res_dirs': [],
68 'additional_res_packages': [],
70 'java_strings_grd%': '',
71 'library_manifest_paths' : [],
72 'resource_input_paths': [],
73 'intermediate_dir': '<(PRODUCT_DIR)/<(_target_name)',
74 'asset_location%': '<(intermediate_dir)/assets',
75 'codegen_stamp': '<(intermediate_dir)/codegen.stamp',
76 'compile_input_paths': [],
77 'package_input_paths': [],
78 'ordered_libraries_file': '<(intermediate_dir)/native_libraries.json',
79 # TODO(cjhopman): build/ shouldn't refer to content/. The libraryloader and
80 # nativelibraries template should be moved out of content/ (to base/?).
81 # http://crbug.com/225101
82 'native_libraries_template': '<(DEPTH)/content/public/android/java/templates/NativeLibraries.template',
83 'native_libraries_java_dir': '<(intermediate_dir)/native_libraries_java/',
84 'native_libraries_java_file': '<(native_libraries_java_dir)/NativeLibraries.java',
85 'native_libraries_java_stamp': '<(intermediate_dir)/native_libraries_java.stamp',
86 'native_libraries_template_data_dir': '<(intermediate_dir)/native_libraries/',
87 'native_libraries_template_data_file': '<(native_libraries_template_data_dir)/native_libraries_array.h',
88 'native_libraries_template_data_stamp': '<(intermediate_dir)/native_libraries_template_data.stamp',
89 'compile_stamp': '<(intermediate_dir)/compile.stamp',
90 'jar_stamp': '<(intermediate_dir)/jar.stamp',
91 'obfuscate_stamp': '<(intermediate_dir)/obfuscate.stamp',
92 'strip_stamp': '<(intermediate_dir)/strip.stamp',
93 'classes_dir': '<(intermediate_dir)/classes',
95 'jar_excluded_classes': [],
96 'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
97 'obfuscated_jar_path': '<(intermediate_dir)/obfuscated.jar',
98 'dex_path': '<(intermediate_dir)/classes.dex',
99 'android_manifest_path%': '<(java_in_dir)/AndroidManifest.xml',
100 'push_stamp': '<(intermediate_dir)/push.stamp',
101 'link_stamp': '<(intermediate_dir)/link.stamp',
102 'package_resources_stamp': '<(intermediate_dir)/package_resources.stamp',
103 'codegen_input_paths': [],
104 'unsigned_apk_path': '<(intermediate_dir)/<(apk_name)-unsigned.apk',
105 'final_apk_path%': '<(PRODUCT_DIR)/apks/<(apk_name).apk',
106 'incomplete_apk_path': '<(intermediate_dir)/<(apk_name)-incomplete.apk',
107 'source_dir': '<(java_in_dir)/src',
108 'apk_install_record': '<(intermediate_dir)/apk_install.record.stamp',
109 'device_intermediate_dir': '/data/local/tmp/chromium/<(_target_name)/<(CONFIGURATION_NAME)',
110 'symlink_script_host_path': '<(intermediate_dir)/create_symlinks.sh',
111 'symlink_script_device_path': '<(device_intermediate_dir)/create_symlinks.sh',
112 'create_standalone_apk%': 1,
115 'native_lib_target%': '',
118 ['gyp_managed_install == 1 and native_lib_target != ""', {
119 'unsigned_standalone_apk_path': '<(intermediate_dir)/<(apk_name)-standalone-unsigned.apk',
121 'unsigned_standalone_apk_path': '<(unsigned_apk_path)',
123 ['gyp_managed_install == 1', {
124 'apk_package_native_libs_dir': '<(intermediate_dir)/libs.managed',
126 'apk_package_native_libs_dir': '<(intermediate_dir)/libs',
130 'native_lib_target%': '',
131 'apk_package_native_libs_dir': '<(apk_package_native_libs_dir)',
132 'unsigned_standalone_apk_path': '<(unsigned_standalone_apk_path)',
134 # Pass the jar path to the apk's "fake" jar target. This would be better as
135 # direct_dependent_settings, but a variable set by a direct_dependent_settings
136 # cannot be lifted in a dependent to all_dependent_settings.
137 'all_dependent_settings': {
139 'apk_output_jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
143 ['resource_dir!=""', {
145 'resource_input_paths': [ '<!@(find <(resource_dir) -name "*")' ]
148 ['R_package != ""', {
150 # We generate R.java in package R_package (in addition to the package
151 # listed in the AndroidManifest.xml, which is unavoidable).
152 'additional_res_dirs': ['<(DEPTH)/build/android/ant/empty/res'],
153 'additional_res_packages': ['<(R_package)'],
154 'additional_R_text_files': ['<(PRODUCT_DIR)/<(package_name)/R.txt'],
157 ['native_lib_target != "" and component == "shared_library"', {
159 '<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
162 ['native_lib_target != ""', {
164 'compile_input_paths': [ '<(native_libraries_java_stamp)' ],
165 'generated_src_dirs': [ '<(native_libraries_java_dir)' ],
166 'native_libs_paths': [
167 '<(SHARED_LIB_DIR)/<(native_lib_target).>(android_product_extension)'
169 'package_input_paths': [
170 '<(apk_package_native_libs_dir)/<(android_app_abi)/gdbserver',
175 # gdbserver is always copied into the APK's native libs dir. The ant
176 # build scripts (apkbuilder task) will only include it in a debug
178 'destination': '<(apk_package_native_libs_dir)/<(android_app_abi)',
180 '<(android_gdbserver)',
187 'input_libraries': ['<@(native_libs_paths)'],
189 'includes': ['../build/android/write_ordered_libraries.gypi'],
192 'action_name': 'native_libraries_template_data_<(_target_name)',
193 'message': 'Creating native_libraries_list.h for <(_target_name).',
195 '<(DEPTH)/build/android/gyp/util/build_utils.py',
196 '<(DEPTH)/build/android/gyp/create_native_libraries_header.py',
197 '<(ordered_libraries_file)',
200 '<(native_libraries_template_data_stamp)',
203 'python', '<(DEPTH)/build/android/gyp/create_native_libraries_header.py',
204 '--ordered-libraries=<(ordered_libraries_file)',
205 '--output=<(native_libraries_template_data_file)',
206 '--stamp=<(native_libraries_template_data_stamp)',
210 'action_name': 'native_libraries_<(_target_name)',
211 'message': 'Creating NativeLibraries.java for <(_target_name).',
213 '<(DEPTH)/build/android/gyp/util/build_utils.py',
214 '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
215 '<(native_libraries_template_data_stamp)',
216 '<(native_libraries_template)',
219 '<(native_libraries_java_stamp)',
222 'python', '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
223 '--include-path=<(native_libraries_template_data_dir)',
224 '--output=<(native_libraries_java_file)',
225 '--template=<(native_libraries_template)',
226 '--stamp=<(native_libraries_java_stamp)',
230 'action_name': 'strip_native_libraries',
232 'ordered_libraries_file%': '<(ordered_libraries_file)',
233 'stripped_libraries_dir': '<(libraries_source_dir)',
234 'input_paths': ['<@(native_libs_paths)'],
235 'stamp': '<(strip_stamp)'
237 'includes': ['../build/android/strip_native_libraries.gypi'],
241 ['gyp_managed_install == 1', {
243 'libraries_top_dir': '<(intermediate_dir)/lib.stripped',
244 'libraries_source_dir': '<(libraries_top_dir)/lib/<(android_app_abi)',
245 'device_library_dir': '<(device_intermediate_dir)/lib.stripped',
248 '<(DEPTH)/tools/android/md5sum/md5sum.gyp:md5sum',
249 '<(DEPTH)/build/android/setup.gyp:get_build_device_configurations',
253 'includes': ['../build/android/push_libraries.gypi'],
256 'action_name': 'create device library symlinks',
257 'message': 'Creating links on device for <(_target_name).',
259 '<(DEPTH)/build/android/gyp/util/build_utils.py',
260 '<(DEPTH)/build/android/gyp/create_device_library_links.py',
261 '<(apk_install_record)',
262 '<(build_device_config_path)',
263 '<(ordered_libraries_file)',
269 'python', '<(DEPTH)/build/android/gyp/create_device_library_links.py',
270 '--build-device-configuration=<(build_device_config_path)',
271 '--libraries-json=<(ordered_libraries_file)',
272 '--script-host-path=<(symlink_script_host_path)',
273 '--script-device-path=<(symlink_script_device_path)',
274 '--target-dir=<(device_library_dir)',
275 '--apk=<(incomplete_apk_path)',
276 '--stamp=<(link_stamp)',
281 ['create_standalone_apk == 1', {
284 'action_name': 'create standalone APK',
287 '<(ordered_libraries_file)',
290 'input_apk_path': '<(unsigned_apk_path)',
291 'output_apk_path': '<(unsigned_standalone_apk_path)',
292 'libraries_top_dir%': '<(libraries_top_dir)',
294 'includes': [ 'android/create_standalone_apk_action.gypi' ],
300 # gyp_managed_install != 1
302 'libraries_source_dir': '<(apk_package_native_libs_dir)/<(android_app_abi)',
303 'package_input_paths': [ '<(strip_stamp)' ],
307 }], # native_lib_target != ''
308 ['gyp_managed_install == 0 or create_standalone_apk == 1', {
311 'action_name': 'finalize standalone apk',
313 'input_apk_path': '<(unsigned_standalone_apk_path)',
314 'output_apk_path': '<(final_apk_path)',
316 'includes': [ 'android/finalize_apk_action.gypi']
320 ['java_strings_grd != ""', {
322 'res_grit_dir': '<(SHARED_INTERMEDIATE_DIR)/<(package_name)_apk/res_grit',
323 'additional_res_dirs': ['<(res_grit_dir)'],
324 # grit_grd_file is used by grit_action.gypi, included below.
325 'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
326 'resource_input_paths': [
327 '<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(res_grit_dir)" <(grit_grd_file))'
332 'action_name': 'generate_localized_strings_xml',
334 'grit_additional_defines': ['-E', 'ANDROID_JAVA_TAGGED_ONLY=false'],
335 'grit_out_dir': '<(res_grit_dir)',
336 # resource_ids is unneeded since we don't generate .h headers.
337 'grit_resource_ids': '',
339 'includes': ['../build/grit_action.gypi'],
343 ['gyp_managed_install == 1', {
346 'action_name': 'finalize incomplete apk',
348 'input_apk_path': '<(unsigned_apk_path)',
349 'output_apk_path': '<(incomplete_apk_path)',
351 'includes': [ 'android/finalize_apk_action.gypi']
354 'action_name': 'apk_install_<(_target_name)',
355 'message': 'Installing <(apk_name).apk',
357 '<(DEPTH)/build/android/gyp/util/build_utils.py',
358 '<(DEPTH)/build/android/gyp/apk_install.py',
359 '<(build_device_config_path)',
360 '<(incomplete_apk_path)',
363 '<(apk_install_record)',
366 'python', '<(DEPTH)/build/android/gyp/apk_install.py',
367 '--android-sdk-tools=<(android_sdk_tools)',
368 '--apk-path=<(incomplete_apk_path)',
369 '--build-device-configuration=<(build_device_config_path)',
370 '--install-record=<(apk_install_record)',
378 'action_name': 'ant_codegen_<(_target_name)',
379 'message': 'Generating R.java for <(_target_name)',
381 ['is_test_apk == 1', {
383 'additional_res_dirs=': [],
384 'additional_res_packages=': [],
389 '<(DEPTH)/build/android/ant/apk-codegen.xml',
390 '<(DEPTH)/build/android/gyp/util/build_utils.py',
391 '<(DEPTH)/build/android/gyp/ant.py',
392 '<(android_manifest_path)',
393 '>@(additional_input_paths)',
394 '>@(codegen_input_paths)',
395 '>@(library_manifest_paths)',
396 '>@(resource_input_paths)',
402 'python', '<(DEPTH)/build/android/gyp/ant.py',
404 '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
405 '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
406 '-DADDITIONAL_R_TEXT_FILES=>(additional_R_text_files)',
407 '-DANDROID_MANIFEST=<(android_manifest_path)',
408 '-DANDROID_SDK_JAR=<(android_sdk_jar)',
409 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
410 '-DANDROID_SDK_VERSION=<(android_sdk_version)',
411 '-DLIBRARY_MANIFEST_PATHS=>(library_manifest_paths)',
412 '-DOUT_DIR=<(intermediate_dir)',
413 '-DRESOURCE_DIR=<(resource_dir)',
415 '-DSTAMP=<(codegen_stamp)',
418 '<(DEPTH)/build/android/ant/apk-codegen.xml',
420 # Add list of inputs to the command line, so if inputs change
421 # (e.g. if a Java file is removed), the command will be re-run.
422 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
423 '-DTHIS_IS_IGNORED=>!(echo \'>(_inputs)\' | md5sum)',
427 'action_name': 'javac_<(_target_name)',
428 'message': 'Compiling java for <(_target_name)',
431 '<(java_in_dir)/src',
432 '<(intermediate_dir)/gen',
433 '>@(additional_src_dirs)',
434 '>@(generated_src_dirs)',
438 '<(DEPTH)/build/android/gyp/util/build_utils.py',
439 '<(DEPTH)/build/android/gyp/javac.py',
440 # If there is a separate find for additional_src_dirs, it will find the
441 # wrong .java files when additional_src_dirs is empty.
442 '>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
443 '>@(input_jars_paths)',
445 '>@(compile_input_paths)',
451 'python', '<(DEPTH)/build/android/gyp/javac.py',
452 '--output-dir=<(classes_dir)',
453 '--classpath=>(input_jars_paths) <(android_sdk_jar)',
454 '--src-dirs=>(all_src_dirs)',
455 '--javac-includes=<(javac_includes)',
456 '--chromium-code=<(chromium_code)',
457 '--stamp=<(compile_stamp)',
459 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
460 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
464 'action_name': 'jar_<(_target_name)',
465 'message': 'Creating <(_target_name) jar',
467 '<(DEPTH)/build/android/gyp/util/build_utils.py',
468 '<(DEPTH)/build/android/gyp/util/md5_check.py',
469 '<(DEPTH)/build/android/gyp/jar.py',
476 'python', '<(DEPTH)/build/android/gyp/jar.py',
477 '--classes-dir=<(classes_dir)',
478 '--jar-path=<(jar_path)',
479 '--excluded-classes=<(jar_excluded_classes)',
480 '--stamp=<(jar_stamp)',
482 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
483 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
487 'action_name': 'ant_obfuscate_<(_target_name)',
488 'message': 'Obfuscating <(_target_name)',
490 '<(DEPTH)/build/android/ant/apk-obfuscate.xml',
491 '<(DEPTH)/build/android/ant/create-test-jar.js',
492 '<(DEPTH)/build/android/gyp/util/build_utils.py',
493 '<(DEPTH)/build/android/gyp/ant.py',
495 '>@(proguard_flags_paths)',
498 '<(obfuscate_stamp)',
501 'python', '<(DEPTH)/build/android/gyp/ant.py',
503 '-DADDITIONAL_SRC_DIRS=>(additional_src_dirs)',
504 '-DANDROID_SDK_JAR=<(android_sdk_jar)',
505 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
506 '-DANDROID_SDK_VERSION=<(android_sdk_version)',
507 '-DAPK_NAME=<(apk_name)',
508 '-DCREATE_TEST_JAR_PATH=<(DEPTH)/build/android/ant/create-test-jar.js',
509 '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
510 '-DGENERATED_SRC_DIRS=>(generated_src_dirs)',
511 '-DINPUT_JARS_PATHS=>(input_jars_paths)',
512 '-DIS_TEST_APK=<(is_test_apk)',
513 '-DJAR_PATH=<(PRODUCT_DIR)/lib.java/<(jar_name)',
514 '-DOBFUSCATED_JAR_PATH=<(obfuscated_jar_path)',
515 '-DOUT_DIR=<(intermediate_dir)',
516 '-DPROGUARD_ENABLED=<(proguard_enabled)',
517 '-DPROGUARD_FLAGS=<(proguard_flags_paths)',
518 '-DTEST_JAR_PATH=<(PRODUCT_DIR)/test.lib.java/<(apk_name).jar',
520 '-DSTAMP=<(obfuscate_stamp)',
523 '<(DEPTH)/build/android/ant/apk-obfuscate.xml',
525 # Add list of inputs to the command line, so if inputs change
526 # (e.g. if a Java file is removed), the command will be re-run.
527 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
528 '-DTHIS_IS_IGNORED=>!(echo \'>(_inputs)\' | md5sum)',
532 'action_name': 'dex_<(_target_name)',
535 ['proguard_enabled == "true"', {
536 'input_paths': [ '<(obfuscate_stamp)' ],
537 'proguard_enabled_input_path': '<(obfuscated_jar_path)',
540 'input_paths': [ '<(compile_stamp)' ],
541 'dex_input_paths': [ '>@(library_dexed_jars_paths)' ],
542 'dex_generated_input_dirs': [ '<(classes_dir)' ],
543 'output_path': '<(dex_path)',
545 'includes': [ 'android/dex_action.gypi' ],
548 'action_name': 'ant package resources',
549 'message': 'Packaging resources for <(_target_name) APK.',
551 '<(DEPTH)/build/android/ant/apk-package-resources.xml',
552 '<(DEPTH)/build/android/gyp/util/build_utils.py',
553 '<(DEPTH)/build/android/gyp/ant.py',
554 '<(android_manifest_path)',
557 '>@(library_manifest_paths)',
558 '>@(additional_input_paths)',
561 ['is_test_apk == 1', {
563 'additional_res_dirs=': [],
564 'additional_res_packages=': [],
569 '<(package_resources_stamp)',
572 'python', '<(DEPTH)/build/android/gyp/ant.py',
574 '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
575 '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
576 '-DADDITIONAL_R_TEXT_FILES=>(additional_R_text_files)',
577 '-DANDROID_SDK_JAR=<(android_sdk_jar)',
578 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
579 '-DAPK_NAME=<(apk_name)',
580 '-DAPP_MANIFEST_VERSION_CODE=<(app_manifest_version_code)',
581 '-DAPP_MANIFEST_VERSION_NAME=<(app_manifest_version_name)',
582 '-DASSET_DIR=<(asset_location)',
583 '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
584 '-DOUT_DIR=<(intermediate_dir)',
585 '-DRESOURCE_DIR=<(resource_dir)',
587 '-DSTAMP=<(package_resources_stamp)',
591 '<(DEPTH)/build/android/ant/apk-package-resources.xml',
593 # Add list of inputs to the command line, so if inputs change
594 # (e.g. if a Java file is removed), the command will be re-run.
595 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
596 '-DTHIS_IS_IGNORED=>!(echo \'>(_inputs)\' | md5sum)',
600 'action_name': 'ant_package_<(_target_name)',
601 'message': 'Packaging <(_target_name).',
603 '<(DEPTH)/build/android/ant/apk-package.xml',
604 '<(DEPTH)/build/android/gyp/util/build_utils.py',
605 '<(DEPTH)/build/android/gyp/ant.py',
608 '<(obfuscate_stamp)',
609 '<(package_resources_stamp)',
610 '>@(package_input_paths)',
613 '<(unsigned_apk_path)',
616 'python', '<(DEPTH)/build/android/gyp/ant.py',
618 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
619 '-DAPK_NAME=<(apk_name)',
620 '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
621 '-DNATIVE_LIBS_DIR=<(apk_package_native_libs_dir)',
622 '-DOUT_DIR=<(intermediate_dir)',
623 '-DSOURCE_DIR=<(source_dir)',
624 '-DUNSIGNED_APK_PATH=<(unsigned_apk_path)',
628 '<(DEPTH)/build/android/ant/apk-package.xml',
630 # Add list of inputs to the command line, so if inputs change
631 # (e.g. if a Java file is removed), the command will be re-run.
632 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
633 '-DTHIS_IS_IGNORED=>!(echo \'>(_inputs)\' | md5sum)',