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.
4
5# This file is meant to be included into a target to provide a rule
6# to build Android APKs in a consistent manner.
7#
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# }
19#
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.
62{
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    'native_lib_placeholder_stamp': '<(apk_package_native_libs_dir)/<(android_app_abi)/native_lib_placeholder.stamp',
177    'native_lib_placeholders': [],
178  },
179  # Pass the jar path to the apk's "fake" jar target.  This would be better as
180  # direct_dependent_settings, but a variable set by a direct_dependent_settings
181  # cannot be lifted in a dependent to all_dependent_settings.
182  'all_dependent_settings': {
183    'conditions': [
184      ['proguard_enabled == "true"', {
185        'variables': {
186          'proguard_enabled': 'true',
187        }
188      }],
189    ],
190    'variables': {
191      'apk_output_jar_path': '<(jar_path)',
192      'tested_apk_obfuscated_jar_path': '<(obfuscated_jar_path)',
193      'tested_apk_dex_path': '<(dex_path)',
194    },
195  },
196  'conditions': [
197    ['resource_dir!=""', {
198      'variables': {
199        'resource_input_paths': [ '<!@(find <(resource_dir) -name "*")' ]
200      },
201    }],
202    ['R_package != ""', {
203      'variables': {
204        # We generate R.java in package R_package (in addition to the package
205        # listed in the AndroidManifest.xml, which is unavoidable).
206        'additional_res_packages': ['<(R_package)'],
207        'additional_R_text_files': ['<(intermediate_dir)/R.txt'],
208      },
209    }],
210    ['native_lib_target != "" and component == "shared_library"', {
211      'dependencies': [
212        '<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
213      ],
214    }],
215    ['use_chromium_linker == 1', {
216      'dependencies': [
217        '<(DEPTH)/base/base.gyp:chromium_android_linker',
218      ],
219    }],
220    ['native_lib_target != ""', {
221      'variables': {
222        'generated_src_dirs': [ '<(native_libraries_java_dir)' ],
223        'native_libs_paths': [
224          '<(SHARED_LIB_DIR)/<(native_lib_target).>(android_product_extension)'
225        ],
226        'package_input_paths': [
227          '<(apk_package_native_libs_dir)/<(android_app_abi)/gdbserver',
228        ],
229      },
230      'copies': [
231        {
232          # gdbserver is always copied into the APK's native libs dir. The ant
233          # build scripts (apkbuilder task) will only include it in a debug
234          # build.
235          'destination': '<(apk_package_native_libs_dir)/<(android_app_abi)',
236          'files': [
237            '<(android_gdbserver)',
238          ],
239        },
240      ],
241      'actions': [
242        {
243          'variables': {
244            'conditions': [
245              ['use_chromium_linker == 1', {
246                'variables': {
247                  'linker_input_libraries': [
248                    '<(SHARED_LIB_DIR)/<(libchromium_android_linker)',
249                  ],
250                }
251              }, {
252                'variables': {
253                  'linker_input_libraries': [],
254                },
255              }],
256            ],
257            'input_libraries': [
258              '<@(native_libs_paths)',
259              '<@(extra_native_libs)',
260              '<@(linker_input_libraries)',
261            ],
262          },
263          'includes': ['../build/android/write_ordered_libraries.gypi'],
264        },
265        {
266          'action_name': 'native_libraries_<(_target_name)',
267          'variables': {
268            'conditions': [
269              ['use_chromium_linker == 1', {
270                'variables': {
271                  'linker_gcc_preprocess_defines': [
272                    '--defines', 'ENABLE_CHROMIUM_LINKER',
273                  ],
274                }
275              }, {
276                'variables': {
277                  'linker_gcc_preprocess_defines': [],
278                },
279              }],
280              ['load_library_from_zip_file == 1', {
281                'variables': {
282                  'linker_load_from_zip_file_preprocess_defines': [
283                    '--defines', 'ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE',
284                  ],
285                }
286              }, {
287                'variables': {
288                  'linker_load_from_zip_file_preprocess_defines': [],
289                },
290              }],
291              ['enable_chromium_linker_tests == 1', {
292                'variables': {
293                  'linker_tests_gcc_preprocess_defines': [
294                    '--defines', 'ENABLE_CHROMIUM_LINKER_TESTS',
295                  ],
296                }
297              }, {
298                'variables': {
299                  'linker_tests_gcc_preprocess_defines': [],
300                },
301              }],
302            ],
303            'gcc_preprocess_defines': [
304              '<@(linker_load_from_zip_file_preprocess_defines)',
305              '<@(linker_gcc_preprocess_defines)',
306              '<@(linker_tests_gcc_preprocess_defines)',
307            ],
308          },
309          'message': 'Creating NativeLibraries.java for <(_target_name)',
310          'inputs': [
311            '<(DEPTH)/build/android/gyp/util/build_utils.py',
312            '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
313            '<(ordered_libraries_file)',
314            '<(native_libraries_template)',
315          ],
316          'outputs': [
317            '<(native_libraries_java_stamp)',
318          ],
319          'action': [
320            'python', '<(DEPTH)/build/android/gyp/gcc_preprocess.py',
321            '--include-path=',
322            '--output=<(native_libraries_java_file)',
323            '--template=<(native_libraries_template)',
324            '--stamp=<(native_libraries_java_stamp)',
325            '--defines', 'NATIVE_LIBRARIES_LIST=@FileArg(<(ordered_libraries_file):java_libraries_list)',
326            '--defines', 'NATIVE_LIBRARIES_VERSION_NUMBER="<(native_lib_version_name)"',
327            '<@(gcc_preprocess_defines)',
328          ],
329        },
330        {
331          'action_name': 'strip_native_libraries',
332          'variables': {
333            'ordered_libraries_file%': '<(ordered_libraries_file)',
334            'stripped_libraries_dir%': '<(stripped_libraries_dir)',
335            'input_paths': [
336              '<@(native_libs_paths)',
337              '<@(extra_native_libs)',
338            ],
339            'stamp': '<(strip_stamp)'
340          },
341          'includes': ['../build/android/strip_native_libraries.gypi'],
342        },
343        {
344          'action_name': 'pack_arm_relocations',
345          'variables': {
346            'conditions': [
347              ['use_chromium_linker == 1 and use_relocation_packer == 1', {
348                'enable_packing': 1,
349              }, {
350                'enable_packing': 0,
351              }],
352            ],
353            'exclude_packing_list': [
354              '<(libchromium_android_linker)',
355            ],
356            'ordered_libraries_file%': '<(ordered_libraries_file)',
357            'stripped_libraries_dir%': '<(stripped_libraries_dir)',
358            'packed_libraries_dir': '<(libraries_source_dir)',
359            'input_paths': [
360              '<(strip_stamp)',
361            ],
362            'stamp': '<(pack_arm_relocations_stamp)',
363          },
364          'includes': ['../build/android/pack_arm_relocations.gypi'],
365        },
366        {
367          'variables': {
368            'input_libraries': [
369              '<@(additional_bundled_libs)',
370            ],
371            'ordered_libraries_file': '<(additional_ordered_libraries_file)',
372            'subtarget': '_additional_libraries',
373          },
374          'includes': ['../build/android/write_ordered_libraries.gypi'],
375        },
376        {
377          'action_name': 'strip_additional_libraries',
378          'variables': {
379            'ordered_libraries_file': '<(additional_ordered_libraries_file)',
380            'stripped_libraries_dir': '<(libraries_source_dir)',
381            'input_paths': [
382              '<@(additional_bundled_libs)',
383              '<(strip_stamp)',
384            ],
385            'stamp': '<(strip_additional_stamp)'
386          },
387          'includes': ['../build/android/strip_native_libraries.gypi'],
388        },
389        {
390          'action_name': 'Create native lib placeholder files for previous releases',
391          'variables': {
392            'placeholders': ['<@(native_lib_placeholders)'],
393            'conditions': [
394              ['gyp_managed_install == 1', {
395                # This "library" just needs to be put in the .apk. It is not loaded
396                # at runtime.
397                'placeholders': ['libfix.crbug.384638.so'],
398              }]
399            ],
400          },
401          'inputs': [
402            '<(DEPTH)/build/android/gyp/create_placeholder_files.py',
403          ],
404          'outputs': [
405            '<(native_lib_placeholder_stamp)',
406          ],
407          'action': [
408            'python', '<(DEPTH)/build/android/gyp/create_placeholder_files.py',
409            '--dest-lib-dir=<(apk_package_native_libs_dir)/<(android_app_abi)/',
410            '--stamp=<(native_lib_placeholder_stamp)',
411            '<@(placeholders)',
412          ],
413        },
414      ],
415      'conditions': [
416        ['gyp_managed_install == 1', {
417          'variables': {
418            'libraries_top_dir': '<(intermediate_dir)/lib.stripped',
419            'libraries_source_dir': '<(libraries_top_dir)/lib/<(android_app_abi)',
420            'device_library_dir': '<(device_intermediate_dir)/lib.stripped',
421            'configuration_name': '<(CONFIGURATION_NAME)',
422          },
423          'dependencies': [
424            '<(DEPTH)/build/android/setup.gyp:get_build_device_configurations',
425          ],
426          'actions': [
427            {
428              'includes': ['../build/android/push_libraries.gypi'],
429            },
430            {
431              'action_name': 'create device library symlinks',
432              'message': 'Creating links on device for <(_target_name)',
433              'inputs': [
434                '<(DEPTH)/build/android/gyp/util/build_utils.py',
435                '<(DEPTH)/build/android/gyp/create_device_library_links.py',
436                '<(apk_install_record)',
437                '<(build_device_config_path)',
438                '<(ordered_libraries_file)',
439              ],
440              'outputs': [
441                '<(link_stamp)'
442              ],
443              'action': [
444                'python', '<(DEPTH)/build/android/gyp/create_device_library_links.py',
445                '--build-device-configuration=<(build_device_config_path)',
446                '--libraries=@FileArg(<(ordered_libraries_file):libraries)',
447                '--script-host-path=<(symlink_script_host_path)',
448                '--script-device-path=<(symlink_script_device_path)',
449                '--target-dir=<(device_library_dir)',
450                '--apk=<(incomplete_apk_path)',
451                '--stamp=<(link_stamp)',
452                '--configuration-name=<(CONFIGURATION_NAME)',
453              ],
454            },
455          ],
456          'conditions': [
457            ['create_standalone_apk == 1', {
458              'actions': [
459                {
460                  'action_name': 'create standalone APK',
461                  'variables': {
462                    'inputs': [
463                      '<(ordered_libraries_file)',
464                      '<(pack_arm_relocations_stamp)',
465                      '<(strip_additional_stamp)',
466                    ],
467                    'input_apk_path': '<(unsigned_apk_path)',
468                    'output_apk_path': '<(unsigned_standalone_apk_path)',
469                    'libraries_top_dir%': '<(libraries_top_dir)',
470                  },
471                  'includes': [ 'android/create_standalone_apk_action.gypi' ],
472                },
473              ],
474            }],
475          ],
476        }, {
477          # gyp_managed_install != 1
478          'variables': {
479            'libraries_source_dir': '<(apk_package_native_libs_dir)/<(android_app_abi)',
480            'package_input_paths': [
481              '<(pack_arm_relocations_stamp)',
482              '<(strip_additional_stamp)',
483            ],
484          },
485        }],
486      ],
487    }], # native_lib_target != ''
488    ['gyp_managed_install == 0 or create_standalone_apk == 1', {
489      'actions': [
490        {
491          'action_name': 'finalize standalone apk',
492          'variables': {
493            'input_apk_path': '<(unsigned_standalone_apk_path)',
494            'output_apk_path': '<(final_apk_path)',
495          },
496          'includes': [ 'android/finalize_apk_action.gypi']
497        },
498      ],
499      'dependencies': [
500        '<(DEPTH)/build/android/rezip.gyp:rezip#host',
501      ],
502    }],
503    ['gyp_managed_install == 1', {
504      'actions': [
505        {
506          'action_name': 'finalize incomplete apk',
507          'variables': {
508            'input_apk_path': '<(unsigned_apk_path)',
509            'output_apk_path': '<(incomplete_apk_path)',
510          },
511          'includes': [ 'android/finalize_apk_action.gypi']
512        },
513        {
514          'action_name': 'apk_install_<(_target_name)',
515          'message': 'Installing <(apk_name).apk',
516          'inputs': [
517            '<(DEPTH)/build/android/gyp/util/build_utils.py',
518            '<(DEPTH)/build/android/gyp/apk_install.py',
519            '<(build_device_config_path)',
520            '<(incomplete_apk_path)',
521          ],
522          'outputs': [
523            '<(apk_install_record)',
524          ],
525          'action': [
526            'python', '<(DEPTH)/build/android/gyp/apk_install.py',
527            '--apk-path=<(incomplete_apk_path)',
528            '--build-device-configuration=<(build_device_config_path)',
529            '--install-record=<(apk_install_record)',
530            '--configuration-name=<(CONFIGURATION_NAME)',
531          ],
532        },
533      ],
534      'dependencies': [
535        '<(DEPTH)/build/android/rezip.gyp:rezip#host',
536      ],
537    }],
538    ['is_test_apk == 1', {
539      'dependencies': [
540        '<(DEPTH)/tools/android/android_tools.gyp:android_tools',
541      ]
542    }],
543  ],
544  'dependencies': [
545    '<(DEPTH)/tools/android/md5sum/md5sum.gyp:md5sum',
546  ],
547  'actions': [
548    {
549      'action_name': 'process_resources',
550      'message': 'processing resources for <(_target_name)',
551      'variables': {
552        # Write the inputs list to a file, so that its mtime is updated when
553        # the list of inputs changes.
554        'inputs_list_file': '>|(apk_codegen.<(_target_name).gypcmd >@(additional_input_paths) >@(resource_input_paths))',
555        'process_resources_options': [],
556        'conditions': [
557          ['is_test_apk == 1', {
558            'dependencies_res_zip_paths=': [],
559            'additional_res_packages=': [],
560          }],
561          ['res_v14_verify_only == 1', {
562            'process_resources_options': ['--v14-verify-only']
563          }],
564        ],
565      },
566      'inputs': [
567        '<(DEPTH)/build/android/gyp/util/build_utils.py',
568        '<(DEPTH)/build/android/gyp/process_resources.py',
569        '<(android_manifest_path)',
570        '>@(additional_input_paths)',
571        '>@(resource_input_paths)',
572        '>@(dependencies_res_zip_paths)',
573        '>(inputs_list_file)',
574      ],
575      'outputs': [
576        '<(resource_zip_path)',
577        '<(generated_proguard_file)',
578        '<(codegen_stamp)',
579      ],
580      'action': [
581        'python', '<(DEPTH)/build/android/gyp/process_resources.py',
582        '--android-sdk', '<(android_sdk)',
583        '--android-sdk-tools', '<(android_sdk_tools)',
584
585        '--android-manifest', '<(android_manifest_path)',
586        '--dependencies-res-zips', '>(dependencies_res_zip_paths)',
587
588        '--extra-res-packages', '>(additional_res_packages)',
589        '--extra-r-text-files', '>(additional_R_text_files)',
590
591        '--proguard-file', '<(generated_proguard_file)',
592
593        '--resource-dirs', '<(resource_dir)',
594        '--resource-zip-out', '<(resource_zip_path)',
595
596        '--R-dir', '<(intermediate_dir)/gen',
597
598        '--stamp', '<(codegen_stamp)',
599
600        '<@(process_resources_options)',
601      ],
602    },
603    {
604      'action_name': 'javac_<(_target_name)',
605      'message': 'Compiling java for <(_target_name)',
606      'variables': {
607        'gen_src_dirs': [
608          '<(intermediate_dir)/gen',
609          '>@(generated_src_dirs)',
610        ],
611        # If there is a separate find for additional_src_dirs, it will find the
612        # wrong .java files when additional_src_dirs is empty.
613        # TODO(thakis): Gyp caches >! evaluation by command. Both java.gypi and
614        # java_apk.gypi evaluate the same command, and at the moment two targets
615        # set java_in_dir to "java". Add a dummy comment here to make sure
616        # that the two targets (one uses java.gypi, the other java_apk.gypi)
617        # get distinct source lists. Medium-term, make targets list all their
618        # Java files instead of using find. (As is, this will be broken if two
619        # targets use the same java_in_dir and both use java_apk.gypi or
620        # both use java.gypi.)
621        'java_sources': ['>!@(find >(java_in_dir)>(java_in_dir_suffix) >(additional_src_dirs) -name "*.java"  # apk)'],
622
623      },
624      'inputs': [
625        '<(DEPTH)/build/android/gyp/util/build_utils.py',
626        '<(DEPTH)/build/android/gyp/javac.py',
627        '>@(java_sources)',
628        '>@(input_jars_paths)',
629        '<(codegen_stamp)',
630      ],
631      'conditions': [
632        ['native_lib_target != ""', {
633          'inputs': [ '<(native_libraries_java_stamp)' ],
634        }],
635      ],
636      'outputs': [
637        '<(compile_stamp)',
638        '<(javac_jar_path)',
639      ],
640      'action': [
641        'python', '<(DEPTH)/build/android/gyp/javac.py',
642        '--classpath=>(input_jars_paths) <(android_sdk_jar)',
643        '--src-gendirs=>(gen_src_dirs)',
644        '--javac-includes=<(javac_includes)',
645        '--chromium-code=<(chromium_code)',
646        '--jar-path=<(javac_jar_path)',
647        '--jar-excluded-classes=<(jar_excluded_classes)',
648        '--stamp=<(compile_stamp)',
649        '>@(java_sources)',
650      ],
651    },
652    {
653      'action_name': 'instr_jar_<(_target_name)',
654      'message': 'Instrumenting <(_target_name) jar',
655      'variables': {
656        'input_path': '<(javac_jar_path)',
657        'output_path': '<(jar_path)',
658        'stamp_path': '<(instr_stamp)',
659        'instr_type': 'jar',
660      },
661      'outputs': [
662        '<(instr_stamp)',
663        '<(jar_path)',
664      ],
665      'inputs': [
666        '<(javac_jar_path)',
667      ],
668      'includes': [ 'android/instr_action.gypi' ],
669    },
670    {
671      'variables': {
672        'src_dirs': [
673          '<(java_in_dir)<(java_in_dir_suffix)',
674          '>@(additional_src_dirs)',
675        ],
676        'lint_jar_path': '<(jar_path)',
677        'stamp_path': '<(lint_stamp)',
678        'result_path': '<(lint_result)',
679        'config_path': '<(lint_config)',
680      },
681      'outputs': [
682        '<(lint_stamp)',
683      ],
684      'includes': [ 'android/lint_action.gypi' ],
685    },
686    {
687      'action_name': 'obfuscate_<(_target_name)',
688      'message': 'Obfuscating <(_target_name)',
689      'variables': {
690        'additional_obfuscate_options': [],
691        'additional_obfuscate_input_paths': [],
692        'proguard_out_dir': '<(intermediate_dir)/proguard',
693        'proguard_input_jar_paths': [
694          '>@(input_jars_paths)',
695          '<(jar_path)',
696        ],
697        'target_conditions': [
698          ['is_test_apk == 1', {
699            'additional_obfuscate_options': [
700              '--testapp',
701            ],
702          }],
703          ['is_test_apk == 1 and tested_apk_obfuscated_jar_path != "/"', {
704            'additional_obfuscate_options': [
705              '--tested-apk-obfuscated-jar-path', '>(tested_apk_obfuscated_jar_path)',
706            ],
707            'additional_obfuscate_input_paths': [
708              '>(tested_apk_obfuscated_jar_path).info',
709            ],
710          }],
711          ['proguard_enabled == "true"', {
712            'additional_obfuscate_options': [
713              '--proguard-enabled',
714            ],
715          }],
716        ],
717        'obfuscate_input_jars_paths': [
718          '>@(input_jars_paths)',
719          '<(jar_path)',
720        ],
721      },
722      'conditions': [
723        ['is_test_apk == 1', {
724          'outputs': [
725            '<(test_jar_path)',
726          ],
727        }],
728      ],
729      'inputs': [
730        '<(DEPTH)/build/android/gyp/apk_obfuscate.py',
731        '<(DEPTH)/build/android/gyp/util/build_utils.py',
732        '>@(proguard_flags_paths)',
733        '>@(obfuscate_input_jars_paths)',
734        '>@(additional_obfuscate_input_paths)',
735        '<(instr_stamp)',
736      ],
737      'outputs': [
738        '<(obfuscate_stamp)',
739
740        # In non-Release builds, these paths will all be empty files.
741        '<(obfuscated_jar_path)',
742        '<(obfuscated_jar_path).info',
743        '<(obfuscated_jar_path).dump',
744        '<(obfuscated_jar_path).seeds',
745        '<(obfuscated_jar_path).mapping',
746        '<(obfuscated_jar_path).usage',
747      ],
748      'action': [
749        'python', '<(DEPTH)/build/android/gyp/apk_obfuscate.py',
750
751        '--configuration-name', '<(CONFIGURATION_NAME)',
752
753        '--android-sdk', '<(android_sdk)',
754        '--android-sdk-tools', '<(android_sdk_tools)',
755        '--android-sdk-jar', '<(android_sdk_jar)',
756
757        '--input-jars-paths=>(proguard_input_jar_paths)',
758        '--proguard-configs=>(proguard_flags_paths)',
759
760
761        '--test-jar-path', '<(test_jar_path)',
762        '--obfuscated-jar-path', '<(obfuscated_jar_path)',
763
764        '--proguard-jar-path', '<(android_sdk_root)/tools/proguard/lib/proguard.jar',
765
766        '--stamp', '<(obfuscate_stamp)',
767
768        '>@(additional_obfuscate_options)',
769      ],
770    },
771    {
772      'action_name': 'dex_<(_target_name)',
773      'variables': {
774        'dex_input_paths': [
775          '>@(library_dexed_jars_paths)',
776          '<(jar_path)',
777        ],
778        'output_path': '<(dex_path)',
779        'proguard_enabled_input_path': '<(obfuscated_jar_path)',
780      },
781      'target_conditions': [
782        ['emma_instrument != 0', {
783          'variables': {
784            'dex_no_locals': 1,
785            'dex_input_paths': [
786              '<(emma_device_jar)'
787            ],
788          },
789        }],
790        ['is_test_apk == 1 and tested_apk_dex_path != "/"', {
791          'variables': {
792            'dex_additional_options': [
793              '--excluded-paths-file', '>(tested_apk_dex_path).inputs'
794            ],
795          },
796          'inputs': [
797            '>(tested_apk_dex_path).inputs',
798          ],
799        }],
800        ['proguard_enabled == "true"', {
801          'inputs': [ '<(obfuscate_stamp)' ]
802        }, {
803          'inputs': [ '<(instr_stamp)' ]
804        }],
805      ],
806      'includes': [ 'android/dex_action.gypi' ],
807    },
808    {
809      'action_name': 'package_resources',
810      'message': 'packaging resources for <(_target_name)',
811      'variables': {
812        'package_resource_zip_input_paths': [
813          '<(resource_zip_path)',
814          '>@(dependencies_res_zip_paths)',
815        ],
816      },
817      'conditions': [
818        ['is_test_apk == 1', {
819          'variables': {
820            'dependencies_res_zip_paths=': [],
821            'additional_res_packages=': [],
822          }
823        }],
824      ],
825      'inputs': [
826        # TODO: This isn't always rerun correctly, http://crbug.com/351928
827        '<(DEPTH)/build/android/gyp/util/build_utils.py',
828        '<(DEPTH)/build/android/gyp/package_resources.py',
829        '<(android_manifest_path)',
830
831        '>@(package_resource_zip_input_paths)',
832
833        '<(codegen_stamp)',
834      ],
835      'outputs': [
836        '<(resource_packaged_apk_path)',
837      ],
838      'action': [
839        'python', '<(DEPTH)/build/android/gyp/package_resources.py',
840        '--android-sdk', '<(android_sdk)',
841        '--android-sdk-tools', '<(android_sdk_tools)',
842
843        '--configuration-name', '<(CONFIGURATION_NAME)',
844
845        '--android-manifest', '<(android_manifest_path)',
846        '--version-code', '<(app_manifest_version_code)',
847        '--version-name', '<(app_manifest_version_name)',
848
849        '--asset-dir', '<(asset_location)',
850        '--resource-zips', '>(package_resource_zip_input_paths)',
851
852        '--no-compress', '<(extensions_to_not_compress)',
853
854        '--apk-path', '<(resource_packaged_apk_path)',
855      ],
856    },
857    {
858      'action_name': 'ant_package_<(_target_name)',
859      'message': 'Packaging <(_target_name)',
860      'variables': {
861        # Write the inputs list to a file, so that its mtime is updated when
862        # the list of inputs changes.
863        'inputs_list_file': '>|(apk_package.<(_target_name).gypcmd >@(package_input_paths))'
864      },
865      'inputs': [
866        '<(DEPTH)/build/android/ant/apk-package.xml',
867        '<(DEPTH)/build/android/gyp/util/build_utils.py',
868        '<(DEPTH)/build/android/gyp/ant.py',
869        '<(dex_path)',
870        '<(codegen_stamp)',
871        '<(obfuscate_stamp)',
872        '<(resource_packaged_apk_path)',
873        '>@(package_input_paths)',
874        '>(inputs_list_file)',
875      ],
876      'outputs': [
877        '<(unsigned_apk_path)',
878      ],
879      'conditions': [
880        ['native_lib_target != ""', {
881          'inputs': ['<(native_lib_placeholder_stamp)'],
882        }],
883      ],
884      'action': [
885        'python', '<(DEPTH)/build/android/gyp/ant.py',
886        '--',
887        '-quiet',
888        '-DDEX_FILE_PATH=<(intermediate_dir)/classes.dex',
889        '-DANDROID_SDK_ROOT=<(android_sdk_root)',
890        '-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
891        '-DRESOURCE_PACKAGED_APK_NAME=<(resource_packaged_apk_name)',
892        '-DAPK_NAME=<(apk_name)',
893        '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
894        '-DNATIVE_LIBS_DIR=<(apk_package_native_libs_dir)',
895        '-DOUT_DIR=<(intermediate_dir)',
896        '-DUNSIGNED_APK_PATH=<(unsigned_apk_path)',
897        '-DEMMA_INSTRUMENT=<(emma_instrument)',
898        '-DEMMA_DEVICE_JAR=<(emma_device_jar)',
899
900        '-Dbasedir=.',
901        '-buildfile',
902        '<(DEPTH)/build/android/ant/apk-package.xml',
903      ]
904    },
905  ],
906}
907