Put back allow_circular_includes_from in GN build.
[chromium-blink-merge.git] / build / java_apk.gypi
blobf32385323dfd94f30743eb93feee0e393ce40df2
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:
9 # {
10 #   'target_name': 'my_package_apk',
11 #   'type': 'none',
12 #   'variables': {
13 #     'apk_name': 'MyPackage',
14 #     'java_in_dir': 'path/to/package/root',
15 #     'resource_dir': 'path/to/package/root/res',
16 #   },
17 #   'includes': ['path/to/this/gypi/file'],
18 # }
20 # Required variables:
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
23 #    <(java_in_dir)/src.
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 #  additional_bundled_libs - Additional libraries what will be stripped and
33 #    bundled in the apk.
34 #  asset_location - The directory where assets are located.
35 #  generated_src_dirs - Same as additional_src_dirs except used for .java files
36 #    that are generated at build time. This should be set automatically by a
37 #    target's dependencies. The .java files in these directories are not
38 #    included in the 'inputs' list (unlike additional_src_dirs).
39 #  input_jars_paths - The path to jars to be included in the classpath. This
40 #    should be filled automatically by depending on the appropriate targets.
41 #  is_test_apk - Set to 1 if building a test apk.  This prevents resources from
42 #    dependencies from being re-included.
43 #  native_lib_target - The target_name of the target which generates the final
44 #    shared library to be included in this apk. A stripped copy of the
45 #    library will be included in the apk.
46 #  resource_dir - The directory for resources.
47 #  R_package - A custom Java package to generate the resource file R.java in.
48 #    By default, the package given in AndroidManifest.xml will be used.
49 #  use_chromium_linker - Enable the content dynamic linker that allows sharing the
50 #    RELRO section of the native libraries between the different processes.
51 #  load_library_from_zip_file - When using the dynamic linker, load the library
52 #    directly out of the zip file.
53 #  use_relocation_packer - Enable relocation packing. Relies on the chromium
54 #    linker, so use_chromium_linker must also be enabled.
55 #  enable_chromium_linker_tests - Enable the content dynamic linker test support
56 #    code. This allows a test APK to inject a Linker.TestRunner instance at
57 #    runtime. Should only be used by the chromium_linker_test_apk target!!
58 #  never_lint - Set to 1 to not run lint on this target.
59 #  java_in_dir_suffix - To override the /src suffix on java_in_dir.
60 #  app_manifest_version_name - set the apps 'human readable' version number.
61 #  app_manifest_version_code - set the apps version number.
63   'variables': {
64     'tested_apk_obfuscated_jar_path%': '/',
65     'tested_apk_dex_path%': '/',
66     'additional_input_paths': [],
67     'input_jars_paths': [],
68     'library_dexed_jars_paths': [],
69     'additional_src_dirs': [],
70     'generated_src_dirs': [],
71     'app_manifest_version_name%': '<(android_app_version_name)',
72     'app_manifest_version_code%': '<(android_app_version_code)',
73     # aapt generates this proguard.txt.
74     'generated_proguard_file': '<(intermediate_dir)/proguard.txt',
75     'proguard_enabled%': 'false',
76     'proguard_flags_paths': ['<(generated_proguard_file)'],
77     'jar_name': 'chromium_apk_<(_target_name).jar',
78     'resource_dir%':'<(DEPTH)/build/android/ant/empty/res',
79     'R_package%':'',
80     'additional_R_text_files': [],
81     'dependencies_res_zip_paths': [],
82     'additional_res_packages': [],
83     'additional_bundled_libs%': [],
84     'is_test_apk%': 0,
85     'extensions_to_not_compress%': '',
86     'resource_input_paths': [],
87     'intermediate_dir': '<(PRODUCT_DIR)/<(_target_name)',
88     'asset_location%': '<(intermediate_dir)/assets',
89     'codegen_stamp': '<(intermediate_dir)/codegen.stamp',
90     'package_input_paths': [],
91     'ordered_libraries_file': '<(intermediate_dir)/native_libraries.json',
92     'additional_ordered_libraries_file': '<(intermediate_dir)/additional_native_libraries.json',
93     'native_libraries_template': '<(DEPTH)/base/android/java/templates/NativeLibraries.template',
94     'native_libraries_java_dir': '<(intermediate_dir)/native_libraries_java/',
95     'native_libraries_java_file': '<(native_libraries_java_dir)/NativeLibraries.java',
96     'native_libraries_java_stamp': '<(intermediate_dir)/native_libraries_java.stamp',
97     'native_libraries_template_data_dir': '<(intermediate_dir)/native_libraries/',
98     'native_libraries_template_data_file': '<(native_libraries_template_data_dir)/native_libraries_array.h',
99     'native_libraries_template_version_file': '<(native_libraries_template_data_dir)/native_libraries_version.h',
100     'compile_stamp': '<(intermediate_dir)/compile.stamp',
101     'lint_stamp': '<(intermediate_dir)/lint.stamp',
102     'lint_result': '<(intermediate_dir)/lint_result.xml',
103     'lint_config': '<(intermediate_dir)/lint_config.xml',
104     'never_lint%': 0,
105     'java_in_dir_suffix%': '/src',
106     'instr_stamp': '<(intermediate_dir)/instr.stamp',
107     'jar_stamp': '<(intermediate_dir)/jar.stamp',
108     'obfuscate_stamp': '<(intermediate_dir)/obfuscate.stamp',
109     'pack_arm_relocations_stamp': '<(intermediate_dir)/pack_arm_relocations.stamp',
110     'strip_stamp': '<(intermediate_dir)/strip.stamp',
111     'stripped_libraries_dir': '<(intermediate_dir)/stripped_libraries',
112     'strip_additional_stamp': '<(intermediate_dir)/strip_additional.stamp',
113     'javac_includes': [],
114     'jar_excluded_classes': [],
115     'javac_jar_path': '<(intermediate_dir)/<(_target_name).javac.jar',
116     'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
117     'obfuscated_jar_path': '<(intermediate_dir)/obfuscated.jar',
118     'test_jar_path': '<(PRODUCT_DIR)/test.lib.java/<(apk_name).jar',
119     'dex_path': '<(intermediate_dir)/classes.dex',
120     'emma_device_jar': '<(android_sdk_root)/tools/lib/emma_device.jar',
121     'android_manifest_path%': '<(java_in_dir)/AndroidManifest.xml',
122     'push_stamp': '<(intermediate_dir)/push.stamp',
123     'link_stamp': '<(intermediate_dir)/link.stamp',
124     'package_resources_stamp': '<(intermediate_dir)/package_resources.stamp',
125     'resource_zip_path': '<(intermediate_dir)/<(_target_name).resources.zip',
126     'resource_packaged_apk_name': '<(apk_name)-resources.ap_',
127     'resource_packaged_apk_path': '<(intermediate_dir)/<(resource_packaged_apk_name)',
128     'unsigned_apk_path': '<(intermediate_dir)/<(apk_name)-unsigned.apk',
129     'final_apk_path%': '<(PRODUCT_DIR)/apks/<(apk_name).apk',
130     'incomplete_apk_path': '<(intermediate_dir)/<(apk_name)-incomplete.apk',
131     'apk_install_record': '<(intermediate_dir)/apk_install.record.stamp',
132     'device_intermediate_dir': '/data/data/org.chromium.gyp_managed_install/<(_target_name)/<(CONFIGURATION_NAME)',
133     'symlink_script_host_path': '<(intermediate_dir)/create_symlinks.sh',
134     'symlink_script_device_path': '<(device_intermediate_dir)/create_symlinks.sh',
135     'create_standalone_apk%': 1,
136     'res_v14_verify_only%': 0,
137     'variables': {
138       'variables': {
139         'native_lib_target%': '',
140         'native_lib_version_name%': '',
141         'use_chromium_linker%' : 0,
142         'load_library_from_zip_file%' : 0,
143         'use_relocation_packer%' : 0,
144         'enable_chromium_linker_tests%': 0,
145         'is_test_apk%': 0,
146       },
147       'conditions': [
148         ['gyp_managed_install == 1 and native_lib_target != ""', {
149           'unsigned_standalone_apk_path': '<(intermediate_dir)/<(apk_name)-standalone-unsigned.apk',
150         }, {
151           'unsigned_standalone_apk_path': '<(unsigned_apk_path)',
152         }],
153         ['gyp_managed_install == 1', {
154           'apk_package_native_libs_dir': '<(intermediate_dir)/libs.managed',
155         }, {
156           'apk_package_native_libs_dir': '<(intermediate_dir)/libs',
157         }],
158         ['is_test_apk == 0 and emma_coverage != 0', {
159           'emma_instrument%': 1,
160         },{
161           'emma_instrument%': 0,
162         }],
163       ],
164     },
165     'native_lib_target%': '',
166     'native_lib_version_name%': '',
167     'use_chromium_linker%' : 0,
168     'load_library_from_zip_file%' : 0,
169     'use_relocation_packer%' : 0,
170     'enable_chromium_linker_tests%': 0,
171     'emma_instrument%': '<(emma_instrument)',
172     'apk_package_native_libs_dir': '<(apk_package_native_libs_dir)',
173     'unsigned_standalone_apk_path': '<(unsigned_standalone_apk_path)',
174     'libchromium_android_linker': 'libchromium_android_linker.>(android_product_extension)',
175     'extra_native_libs': [],
176   },
177   # Pass the jar path to the apk's "fake" jar target.  This would be better as
178   # direct_dependent_settings, but a variable set by a direct_dependent_settings
179   # cannot be lifted in a dependent to all_dependent_settings.
180   'all_dependent_settings': {
181     'conditions': [
182       ['proguard_enabled == "true"', {
183         'variables': {
184           'proguard_enabled': 'true',
185         }
186       }],
187     ],
188     'variables': {
189       'apk_output_jar_path': '<(jar_path)',
190       'tested_apk_obfuscated_jar_path': '<(obfuscated_jar_path)',
191       'tested_apk_dex_path': '<(dex_path)',
192     },
193   },
194   'conditions': [
195     ['resource_dir!=""', {
196       'variables': {
197         'resource_input_paths': [ '<!@(find <(resource_dir) -name "*")' ]
198       },
199     }],
200     ['R_package != ""', {
201       'variables': {
202         # We generate R.java in package R_package (in addition to the package
203         # listed in the AndroidManifest.xml, which is unavoidable).
204         'additional_res_packages': ['<(R_package)'],
205         'additional_R_text_files': ['<(intermediate_dir)/R.txt'],
206       },
207     }],
208     ['native_lib_target != "" and component == "shared_library"', {
209       'dependencies': [
210         '<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
211       ],
212     }],
213     ['use_chromium_linker == 1', {
214       'dependencies': [
215         '<(DEPTH)/base/base.gyp:chromium_android_linker',
216       ],
217     }],
218     ['native_lib_target != ""', {
219       'variables': {
220         'generated_src_dirs': [ '<(native_libraries_java_dir)' ],
221         'native_libs_paths': [
222           '<(SHARED_LIB_DIR)/<(native_lib_target).>(android_product_extension)'
223         ],
224         'package_input_paths': [
225           '<(apk_package_native_libs_dir)/<(android_app_abi)/gdbserver',
226         ],
227       },
228       'copies': [
229         {
230           # gdbserver is always copied into the APK's native libs dir. The ant
231           # build scripts (apkbuilder task) will only include it in a debug
232           # build.
233           'destination': '<(apk_package_native_libs_dir)/<(android_app_abi)',
234           'files': [
235             '<(android_gdbserver)',
236           ],
237         },
238       ],
239       'actions': [
240         {
241           'variables': {
242             'conditions': [
243               ['use_chromium_linker == 1', {
244                 'variables': {
245                   'linker_input_libraries': [
246                     '<(SHARED_LIB_DIR)/<(libchromium_android_linker)',
247                   ],
248                 }
249               }, {
250                 'variables': {
251                   'linker_input_libraries': [],
252                 },
253               }],
254             ],
255             'input_libraries': [
256               '<@(native_libs_paths)',
257               '<@(extra_native_libs)',
258               '<@(linker_input_libraries)',
259             ],
260           },
261           'includes': ['../build/android/write_ordered_libraries.gypi'],
262         },
263         {
264           'action_name': 'native_libraries_<(_target_name)',
265           'variables': {
266             'conditions': [
267               ['use_chromium_linker == 1', {
268                 'variables': {
269                   'linker_gcc_preprocess_defines': [
270                     '--defines', 'ENABLE_CHROMIUM_LINKER',
271                   ],
272                 }
273               }, {
274                 'variables': {
275                   'linker_gcc_preprocess_defines': [],
276                 },
277               }],
278               ['load_library_from_zip_file == 1', {
279                 'variables': {
280                   'linker_load_from_zip_file_preprocess_defines': [
281                     '--defines', 'ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE',
282                   ],
283                 }
284               }, {
285                 'variables': {
286                   'linker_load_from_zip_file_preprocess_defines': [],
287                 },
288               }],
289               ['enable_chromium_linker_tests == 1', {
290                 'variables': {
291                   'linker_tests_gcc_preprocess_defines': [
292                     '--defines', 'ENABLE_CHROMIUM_LINKER_TESTS',
293                   ],
294                 }
295               }, {
296                 'variables': {
297                   'linker_tests_gcc_preprocess_defines': [],
298                 },
299               }],
300             ],
301             'gcc_preprocess_defines': [
302               '<@(linker_load_from_zip_file_preprocess_defines)',
303               '<@(linker_gcc_preprocess_defines)',
304               '<@(linker_tests_gcc_preprocess_defines)',
305             ],
306           },
307           'message': 'Creating NativeLibraries.java for <(_target_name)',
308           'inputs': [
309             '<(DEPTH)/build/android/gyp/util/build_utils.py',
310             '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
311             '<(ordered_libraries_file)',
312             '<(native_libraries_template)',
313           ],
314           'outputs': [
315             '<(native_libraries_java_stamp)',
316           ],
317           'action': [
318             'python', '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
319             '--include-path=',
320             '--output=<(native_libraries_java_file)',
321             '--template=<(native_libraries_template)',
322             '--stamp=<(native_libraries_java_stamp)',
323             '--defines', 'NATIVE_LIBRARIES_LIST=@FileArg(<(ordered_libraries_file):java_libraries_list)',
324             '--defines', 'NATIVE_LIBRARIES_VERSION_NUMBER="<(native_lib_version_name)"',
325             '<@(gcc_preprocess_defines)',
326           ],
327         },
328         {
329           'action_name': 'strip_native_libraries',
330           'variables': {
331             'ordered_libraries_file%': '<(ordered_libraries_file)',
332             'stripped_libraries_dir%': '<(stripped_libraries_dir)',
333             'input_paths': [
334               '<@(native_libs_paths)',
335               '<@(extra_native_libs)',
336             ],
337             'stamp': '<(strip_stamp)'
338           },
339           'includes': ['../build/android/strip_native_libraries.gypi'],
340         },
341         {
342           'action_name': 'pack_arm_relocations',
343           'variables': {
344             'conditions': [
345               ['use_chromium_linker == 1 and use_relocation_packer == 1', {
346                 'enable_packing': 1,
347               }, {
348                 'enable_packing': 0,
349               }],
350             ],
351             'exclude_packing_list': [
352               '<(libchromium_android_linker)',
353             ],
354             'ordered_libraries_file%': '<(ordered_libraries_file)',
355             'stripped_libraries_dir%': '<(stripped_libraries_dir)',
356             'packed_libraries_dir': '<(libraries_source_dir)',
357             'input_paths': [
358               '<(strip_stamp)',
359             ],
360             'stamp': '<(pack_arm_relocations_stamp)',
361           },
362           'includes': ['../build/android/pack_arm_relocations.gypi'],
363         },
364         {
365           'variables': {
366             'input_libraries': [
367               '<@(additional_bundled_libs)',
368             ],
369             'ordered_libraries_file': '<(additional_ordered_libraries_file)',
370             'subtarget': '_additional_libraries',
371           },
372           'includes': ['../build/android/write_ordered_libraries.gypi'],
373         },
374         {
375           'action_name': 'strip_additional_libraries',
376           'variables': {
377             'ordered_libraries_file': '<(additional_ordered_libraries_file)',
378             'stripped_libraries_dir': '<(libraries_source_dir)',
379             'input_paths': [
380               '<@(additional_bundled_libs)',
381               '<(strip_stamp)',
382             ],
383             'stamp': '<(strip_additional_stamp)'
384           },
385           'includes': ['../build/android/strip_native_libraries.gypi'],
386         },
387       ],
388       'conditions': [
389         ['gyp_managed_install == 1', {
390           'variables': {
391             # This "library" just needs to be put in the .apk. It is not loaded
392             # at runtime.
393             'placeholder_native_library_path':
394               '<(apk_package_native_libs_dir)/<(android_app_abi)/libfix.crbug.384638.so',
395             'package_input_paths': [ '<(placeholder_native_library_path)' ],
396             'libraries_top_dir': '<(intermediate_dir)/lib.stripped',
397             'libraries_source_dir': '<(libraries_top_dir)/lib/<(android_app_abi)',
398             'device_library_dir': '<(device_intermediate_dir)/lib.stripped',
399             'configuration_name': '<(CONFIGURATION_NAME)',
400           },
401           'dependencies': [
402             '<(DEPTH)/build/android/setup.gyp:get_build_device_configurations',
403           ],
404           'actions': [
405             {
406               'includes': ['../build/android/push_libraries.gypi'],
407             },
408             {
409               'action_name': 'create placeholder lib',
410               'inputs': [
411                 '<(DEPTH)/build/android/gyp/touch.py',
412               ],
413               'outputs': [
414                 '<(placeholder_native_library_path)',
415               ],
416               'action' : [
417                 'python', '<(DEPTH)/build/android/gyp/touch.py',
418                 '<@(_outputs)',
419               ],
420             },
421             {
422               'action_name': 'create device library symlinks',
423               'message': 'Creating links on device for <(_target_name)',
424               'inputs': [
425                 '<(DEPTH)/build/android/gyp/util/build_utils.py',
426                 '<(DEPTH)/build/android/gyp/create_device_library_links.py',
427                 '<(apk_install_record)',
428                 '<(build_device_config_path)',
429                 '<(ordered_libraries_file)',
430               ],
431               'outputs': [
432                 '<(link_stamp)'
433               ],
434               'action': [
435                 'python', '<(DEPTH)/build/android/gyp/create_device_library_links.py',
436                 '--build-device-configuration=<(build_device_config_path)',
437                 '--libraries=@FileArg(<(ordered_libraries_file):libraries)',
438                 '--script-host-path=<(symlink_script_host_path)',
439                 '--script-device-path=<(symlink_script_device_path)',
440                 '--target-dir=<(device_library_dir)',
441                 '--apk=<(incomplete_apk_path)',
442                 '--stamp=<(link_stamp)',
443                 '--configuration-name=<(CONFIGURATION_NAME)',
444               ],
445             },
446           ],
447           'conditions': [
448             ['create_standalone_apk == 1', {
449               'actions': [
450                 {
451                   'action_name': 'create standalone APK',
452                   'variables': {
453                     'inputs': [
454                       '<(ordered_libraries_file)',
455                       '<(pack_arm_relocations_stamp)',
456                       '<(strip_additional_stamp)',
457                     ],
458                     'input_apk_path': '<(unsigned_apk_path)',
459                     'output_apk_path': '<(unsigned_standalone_apk_path)',
460                     'libraries_top_dir%': '<(libraries_top_dir)',
461                   },
462                   'includes': [ 'android/create_standalone_apk_action.gypi' ],
463                 },
464               ],
465             }],
466           ],
467         }, {
468           # gyp_managed_install != 1
469           'variables': {
470             'libraries_source_dir': '<(apk_package_native_libs_dir)/<(android_app_abi)',
471             'package_input_paths': [
472               '<(pack_arm_relocations_stamp)',
473               '<(strip_additional_stamp)',
474             ],
475           },
476         }],
477       ],
478     }], # native_lib_target != ''
479     ['gyp_managed_install == 0 or create_standalone_apk == 1', {
480       'actions': [
481         {
482           'action_name': 'finalize standalone apk',
483           'variables': {
484             'input_apk_path': '<(unsigned_standalone_apk_path)',
485             'output_apk_path': '<(final_apk_path)',
486           },
487           'includes': [ 'android/finalize_apk_action.gypi']
488         },
489       ],
490       'dependencies': [
491         '<(DEPTH)/build/android/rezip.gyp:rezip#host',
492       ],
493     }],
494     ['gyp_managed_install == 1', {
495       'actions': [
496         {
497           'action_name': 'finalize incomplete apk',
498           'variables': {
499             'input_apk_path': '<(unsigned_apk_path)',
500             'output_apk_path': '<(incomplete_apk_path)',
501           },
502           'includes': [ 'android/finalize_apk_action.gypi']
503         },
504         {
505           'action_name': 'apk_install_<(_target_name)',
506           'message': 'Installing <(apk_name).apk',
507           'inputs': [
508             '<(DEPTH)/build/android/gyp/util/build_utils.py',
509             '<(DEPTH)/build/android/gyp/apk_install.py',
510             '<(build_device_config_path)',
511             '<(incomplete_apk_path)',
512           ],
513           'outputs': [
514             '<(apk_install_record)',
515           ],
516           'action': [
517             'python', '<(DEPTH)/build/android/gyp/apk_install.py',
518             '--apk-path=<(incomplete_apk_path)',
519             '--build-device-configuration=<(build_device_config_path)',
520             '--install-record=<(apk_install_record)',
521             '--configuration-name=<(CONFIGURATION_NAME)',
522           ],
523         },
524       ],
525       'dependencies': [
526         '<(DEPTH)/build/android/rezip.gyp:rezip#host',
527       ],
528     }],
529     ['is_test_apk == 1', {
530       'dependencies': [
531         '<(DEPTH)/tools/android/android_tools.gyp:android_tools',
532       ]
533     }],
534   ],
535   'dependencies': [
536     '<(DEPTH)/tools/android/md5sum/md5sum.gyp:md5sum',
537   ],
538   'actions': [
539     {
540       'action_name': 'process_resources',
541       'message': 'processing resources for <(_target_name)',
542       'variables': {
543         # Write the inputs list to a file, so that its mtime is updated when
544         # the list of inputs changes.
545         'inputs_list_file': '>|(apk_codegen.<(_target_name).gypcmd >@(additional_input_paths) >@(resource_input_paths))',
546         'process_resources_options': [],
547         'conditions': [
548           ['is_test_apk == 1', {
549             'dependencies_res_zip_paths=': [],
550             'additional_res_packages=': [],
551           }],
552           ['res_v14_verify_only == 1', {
553             'process_resources_options': ['--v14-verify-only']
554           }],
555         ],
556       },
557       'inputs': [
558         '<(DEPTH)/build/android/gyp/util/build_utils.py',
559         '<(DEPTH)/build/android/gyp/process_resources.py',
560         '<(android_manifest_path)',
561         '>@(additional_input_paths)',
562         '>@(resource_input_paths)',
563         '>@(dependencies_res_zip_paths)',
564         '>(inputs_list_file)',
565       ],
566       'outputs': [
567         '<(resource_zip_path)',
568         '<(generated_proguard_file)',
569         '<(codegen_stamp)',
570       ],
571       'action': [
572         'python', '<(DEPTH)/build/android/gyp/process_resources.py',
573         '--android-sdk', '<(android_sdk)',
574         '--android-sdk-tools', '<(android_sdk_tools)',
576         '--android-manifest', '<(android_manifest_path)',
577         '--dependencies-res-zips', '>(dependencies_res_zip_paths)',
579         '--extra-res-packages', '>(additional_res_packages)',
580         '--extra-r-text-files', '>(additional_R_text_files)',
582         '--proguard-file', '<(generated_proguard_file)',
584         '--resource-dirs', '<(resource_dir)',
585         '--resource-zip-out', '<(resource_zip_path)',
587         '--R-dir', '<(intermediate_dir)/gen',
589         '--stamp', '<(codegen_stamp)',
591         '<@(process_resources_options)',
592       ],
593     },
594     {
595       'action_name': 'javac_<(_target_name)',
596       'message': 'Compiling java for <(_target_name)',
597       'variables': {
598         'gen_src_dirs': [
599           '<(intermediate_dir)/gen',
600           '>@(generated_src_dirs)',
601         ],
602         # If there is a separate find for additional_src_dirs, it will find the
603         # wrong .java files when additional_src_dirs is empty.
604         # TODO(thakis): Gyp caches >! evaluation by command. Both java.gypi and
605         # java_apk.gypi evaluate the same command, and at the moment two targets
606         # set java_in_dir to "java". Add a dummy comment here to make sure
607         # that the two targets (one uses java.gypi, the other java_apk.gypi)
608         # get distinct source lists. Medium-term, make targets list all their
609         # Java files instead of using find. (As is, this will be broken if two
610         # targets use the same java_in_dir and both use java_apk.gypi or
611         # both use java.gypi.)
612         'java_sources': ['>!@(find >(java_in_dir)>(java_in_dir_suffix) >(additional_src_dirs) -name "*.java"  # apk)'],
614       },
615       'inputs': [
616         '<(DEPTH)/build/android/gyp/util/build_utils.py',
617         '<(DEPTH)/build/android/gyp/javac.py',
618         '>@(java_sources)',
619         '>@(input_jars_paths)',
620         '<(codegen_stamp)',
621       ],
622       'conditions': [
623         ['native_lib_target != ""', {
624           'inputs': [ '<(native_libraries_java_stamp)' ],
625         }],
626       ],
627       'outputs': [
628         '<(compile_stamp)',
629         '<(javac_jar_path)',
630       ],
631       'action': [
632         'python', '<(DEPTH)/build/android/gyp/javac.py',
633         '--classpath=>(input_jars_paths) <(android_sdk_jar)',
634         '--src-gendirs=>(gen_src_dirs)',
635         '--javac-includes=<(javac_includes)',
636         '--chromium-code=<(chromium_code)',
637         '--jar-path=<(javac_jar_path)',
638         '--jar-excluded-classes=<(jar_excluded_classes)',
639         '--stamp=<(compile_stamp)',
640         '>@(java_sources)',
641       ],
642     },
643     {
644       'action_name': 'instr_jar_<(_target_name)',
645       'message': 'Instrumenting <(_target_name) jar',
646       'variables': {
647         'input_path': '<(javac_jar_path)',
648         'output_path': '<(jar_path)',
649         'stamp_path': '<(instr_stamp)',
650         'instr_type': 'jar',
651       },
652       'outputs': [
653         '<(instr_stamp)',
654         '<(jar_path)',
655       ],
656       'inputs': [
657         '<(javac_jar_path)',
658       ],
659       'includes': [ 'android/instr_action.gypi' ],
660     },
661     {
662       'variables': {
663         'src_dirs': [
664           '<(java_in_dir)<(java_in_dir_suffix)',
665           '>@(additional_src_dirs)',
666         ],
667         'lint_jar_path': '<(jar_path)',
668         'stamp_path': '<(lint_stamp)',
669         'result_path': '<(lint_result)',
670         'config_path': '<(lint_config)',
671       },
672       'outputs': [
673         '<(lint_stamp)',
674       ],
675       'includes': [ 'android/lint_action.gypi' ],
676     },
677     {
678       'action_name': 'obfuscate_<(_target_name)',
679       'message': 'Obfuscating <(_target_name)',
680       'variables': {
681         'additional_obfuscate_options': [],
682         'additional_obfuscate_input_paths': [],
683         'proguard_out_dir': '<(intermediate_dir)/proguard',
684         'proguard_input_jar_paths': [
685           '>@(input_jars_paths)',
686           '<(jar_path)',
687         ],
688         'target_conditions': [
689           ['is_test_apk == 1', {
690             'additional_obfuscate_options': [
691               '--testapp',
692             ],
693           }],
694           ['is_test_apk == 1 and tested_apk_obfuscated_jar_path != "/"', {
695             'additional_obfuscate_options': [
696               '--tested-apk-obfuscated-jar-path', '>(tested_apk_obfuscated_jar_path)',
697             ],
698             'additional_obfuscate_input_paths': [
699               '>(tested_apk_obfuscated_jar_path).info',
700             ],
701           }],
702           ['proguard_enabled == "true"', {
703             'additional_obfuscate_options': [
704               '--proguard-enabled',
705             ],
706           }],
707         ],
708         'obfuscate_input_jars_paths': [
709           '>@(input_jars_paths)',
710           '<(jar_path)',
711         ],
712       },
713       'conditions': [
714         ['is_test_apk == 1', {
715           'outputs': [
716             '<(test_jar_path)',
717           ],
718         }],
719       ],
720       'inputs': [
721         '<(DEPTH)/build/android/gyp/apk_obfuscate.py',
722         '<(DEPTH)/build/android/gyp/util/build_utils.py',
723         '>@(proguard_flags_paths)',
724         '>@(obfuscate_input_jars_paths)',
725         '>@(additional_obfuscate_input_paths)',
726         '<(instr_stamp)',
727       ],
728       'outputs': [
729         '<(obfuscate_stamp)',
731         # In non-Release builds, these paths will all be empty files.
732         '<(obfuscated_jar_path)',
733         '<(obfuscated_jar_path).info',
734         '<(obfuscated_jar_path).dump',
735         '<(obfuscated_jar_path).seeds',
736         '<(obfuscated_jar_path).mapping',
737         '<(obfuscated_jar_path).usage',
738       ],
739       'action': [
740         'python', '<(DEPTH)/build/android/gyp/apk_obfuscate.py',
742         '--configuration-name', '<(CONFIGURATION_NAME)',
744         '--android-sdk', '<(android_sdk)',
745         '--android-sdk-tools', '<(android_sdk_tools)',
746         '--android-sdk-jar', '<(android_sdk_jar)',
748         '--input-jars-paths=>(proguard_input_jar_paths)',
749         '--proguard-configs=>(proguard_flags_paths)',
752         '--test-jar-path', '<(test_jar_path)',
753         '--obfuscated-jar-path', '<(obfuscated_jar_path)',
755         '--proguard-jar-path', '<(android_sdk_root)/tools/proguard/lib/proguard.jar',
757         '--stamp', '<(obfuscate_stamp)',
759         '>@(additional_obfuscate_options)',
760       ],
761     },
762     {
763       'action_name': 'dex_<(_target_name)',
764       'variables': {
765         'dex_input_paths': [
766           '>@(library_dexed_jars_paths)',
767           '<(jar_path)',
768         ],
769         'output_path': '<(dex_path)',
770         'proguard_enabled_input_path': '<(obfuscated_jar_path)',
771       },
772       'target_conditions': [
773         ['emma_instrument != 0', {
774           'variables': {
775             'dex_no_locals': 1,
776             'dex_input_paths': [
777               '<(emma_device_jar)'
778             ],
779           },
780         }],
781         ['is_test_apk == 1 and tested_apk_dex_path != "/"', {
782           'variables': {
783             'dex_additional_options': [
784               '--excluded-paths-file', '>(tested_apk_dex_path).inputs'
785             ],
786           },
787           'inputs': [
788             '>(tested_apk_dex_path).inputs',
789           ],
790         }],
791         ['proguard_enabled == "true"', {
792           'inputs': [ '<(obfuscate_stamp)' ]
793         }, {
794           'inputs': [ '<(instr_stamp)' ]
795         }],
796       ],
797       'includes': [ 'android/dex_action.gypi' ],
798     },
799     {
800       'action_name': 'package_resources',
801       'message': 'packaging resources for <(_target_name)',
802       'variables': {
803         'package_resource_zip_input_paths': [
804           '<(resource_zip_path)',
805           '>@(dependencies_res_zip_paths)',
806         ],
807       },
808       'conditions': [
809         ['is_test_apk == 1', {
810           'variables': {
811             'dependencies_res_zip_paths=': [],
812             'additional_res_packages=': [],
813           }
814         }],
815       ],
816       'inputs': [
817         # TODO: This isn't always rerun correctly, http://crbug.com/351928
818         '<(DEPTH)/build/android/gyp/util/build_utils.py',
819         '<(DEPTH)/build/android/gyp/package_resources.py',
820         '<(android_manifest_path)',
822         '>@(package_resource_zip_input_paths)',
824         '<(codegen_stamp)',
825       ],
826       'outputs': [
827         '<(resource_packaged_apk_path)',
828       ],
829       'action': [
830         'python', '<(DEPTH)/build/android/gyp/package_resources.py',
831         '--android-sdk', '<(android_sdk)',
832         '--android-sdk-tools', '<(android_sdk_tools)',
834         '--configuration-name', '<(CONFIGURATION_NAME)',
836         '--android-manifest', '<(android_manifest_path)',
837         '--version-code', '<(app_manifest_version_code)',
838         '--version-name', '<(app_manifest_version_name)',
840         '--asset-dir', '<(asset_location)',
841         '--resource-zips', '>(package_resource_zip_input_paths)',
843         '--no-compress', '<(extensions_to_not_compress)',
845         '--apk-path', '<(resource_packaged_apk_path)',
846       ],
847     },
848     {
849       'action_name': 'ant_package_<(_target_name)',
850       'message': 'Packaging <(_target_name)',
851       'variables': {
852         # Write the inputs list to a file, so that its mtime is updated when
853         # the list of inputs changes.
854         'inputs_list_file': '>|(apk_package.<(_target_name).gypcmd >@(package_input_paths))'
855       },
856       'inputs': [
857         '<(DEPTH)/build/android/ant/apk-package.xml',
858         '<(DEPTH)/build/android/gyp/util/build_utils.py',
859         '<(DEPTH)/build/android/gyp/ant.py',
860         '<(dex_path)',
861         '<(codegen_stamp)',
862         '<(obfuscate_stamp)',
863         '<(resource_packaged_apk_path)',
864         '>@(package_input_paths)',
865         '>(inputs_list_file)',
866       ],
867       'outputs': [
868         '<(unsigned_apk_path)',
869       ],
870       'action': [
871         'python', '<(DEPTH)/build/android/gyp/ant.py',
872         '--',
873         '-quiet',
874         '-DDEX_FILE_PATH=<(intermediate_dir)/classes.dex',
875         '-DANDROID_SDK_ROOT=<(android_sdk_root)',
876         '-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
877         '-DRESOURCE_PACKAGED_APK_NAME=<(resource_packaged_apk_name)',
878         '-DAPK_NAME=<(apk_name)',
879         '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
880         '-DNATIVE_LIBS_DIR=<(apk_package_native_libs_dir)',
881         '-DOUT_DIR=<(intermediate_dir)',
882         '-DUNSIGNED_APK_PATH=<(unsigned_apk_path)',
883         '-DEMMA_INSTRUMENT=<(emma_instrument)',
884         '-DEMMA_DEVICE_JAR=<(emma_device_jar)',
886         '-Dbasedir=.',
887         '-buildfile',
888         '<(DEPTH)/build/android/ant/apk-package.xml',
889       ]
890     },
891   ],