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': '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 (default:
33 # <(ant_build_out)/<(_target_name)/assets).
34 # generated_src_dirs - Same as additional_src_dirs except used for .java files
35 # that are generated at build time. This should be set automatically by a
36 # target's dependencies. The .java files in these directories are not
37 # included in the 'inputs' list (unlike additional_src_dirs).
38 # input_jars_paths - The path to jars to be included in the classpath. This
39 # should be filled automatically by depending on the appropriate targets.
40 # is_test_apk - Set to 1 if building a test apk. This prevents resources from
41 # dependencies from being re-included.
42 # native_libs_paths - The path to any native library to be included in this
43 # target. This should be a path in <(SHARED_LIB_DIR). A stripped copy of
44 # the library will be included in the apk.
45 # resource_dir - The directory for resources.
46 # R_package - A custom Java package to generate the resource file R.java in.
47 # By default, the package given in AndroidManifest.xml will be used.
48 # java_strings_grd - The name of the grd file from which to generate localized
49 # strings.xml files, if any.
53 'asset_location%': '',
54 'additional_input_paths': [],
55 'input_jars_paths': [],
56 'additional_src_dirs': [],
57 'generated_src_dirs': [],
58 'app_manifest_version_name%': '<(android_app_version_name)',
59 'app_manifest_version_code%': '<(android_app_version_code)',
60 'proguard_enabled%': 'false',
61 'proguard_flags%': '',
62 'native_libs_paths': [],
63 'jar_name%': 'chromium_apk_<(_target_name).jar',
66 'additional_res_dirs': [],
67 'additional_res_packages': [],
69 'java_strings_grd%': '',
73 '<@(native_libs_paths)'
75 # Pass the jar path to the apk's "fake" jar target. This would be better as
76 # direct_dependent_settings, but a variable set by a direct_dependent_settings
77 # cannot be lifted in a dependent to all_dependent_settings.
78 'all_dependent_settings': {
80 'apk_output_jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
85 'rule_name': 'copy_and_strip_native_libraries',
88 'apk_libraries_dir': '<(PRODUCT_DIR)/<(_target_name)/libs/<(android_app_abi)',
89 'stripped_library_path': '<(apk_libraries_dir)/<(RULE_INPUT_ROOT).so',
92 '<(DEPTH)/build/android/strip_library_for_apk.py',
95 '<(stripped_library_path)',
98 'python', '<(DEPTH)/build/android/strip_library_for_apk.py',
99 '--android-strip=<(android_strip)',
100 '--android-strip-arg=--strip-unneeded',
101 '--stripped-libraries-dir=<(apk_libraries_dir)',
102 '<(RULE_INPUT_PATH)',
107 ['R_package != ""', {
109 # We generate R.java in package R_package (in addition to the package
110 # listed in the AndroidManifest.xml, which is unavoidable).
111 'additional_res_dirs': ['<(DEPTH)/build/android/ant/empty/res'],
112 'additional_res_packages': ['<(R_package)'],
113 'additional_R_text_files': ['<(PRODUCT_DIR)/<(package_name)/R.txt'],
116 ['java_strings_grd != ""', {
118 'out_res_dir': '<(SHARED_INTERMEDIATE_DIR)/<(package_name)_apk/res',
119 'additional_res_dirs': ['<(out_res_dir)'],
120 # grit_grd_file is used by grit_action.gypi, included below.
121 'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
125 'action_name': 'generate_localized_strings_xml',
127 'grit_out_dir': '<(out_res_dir)',
128 # resource_ids is unneeded since we don't generate .h headers.
129 'grit_resource_ids': '',
131 'includes': ['../build/grit_action.gypi'],
138 'action_name': 'ant_<(_target_name)',
139 'message': 'Building <(_target_name).',
141 '<(java_in_dir)/AndroidManifest.xml',
142 '<(DEPTH)/build/android/ant/chromium-apk.xml',
143 '<(DEPTH)/build/android/ant/common.xml',
144 '<(DEPTH)/build/android/ant/apk-build.xml',
145 # If there is a separate find for additional_src_dirs, it will find the
146 # wrong .java files when additional_src_dirs is empty.
147 '>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
148 '>@(input_jars_paths)',
149 '>@(native_libs_paths)',
150 '>@(additional_input_paths)',
153 ['resource_dir!=""', {
154 'inputs': ['<!@(find <(java_in_dir)/<(resource_dir) -name "*")']
156 ['java_strings_grd != ""', {
158 # TODO(newt): replace this with .../values/strings.xml once
159 # the English strings.xml is generated as well? That would be
160 # simpler and faster and should be equivalent.
161 '<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(out_res_dir)" <(grit_grd_file))',
164 ['is_test_apk == 1', {
166 'additional_res_dirs=': [],
167 'additional_res_packages=': [],
170 ['proguard_enabled == "true" and proguard_flags != ""', {
171 'inputs': ['<(java_in_dir)/<(proguard_flags)']
175 '<(PRODUCT_DIR)/apks/<(apk_name).apk',
179 '-DAPP_ABI=<(android_app_abi)',
180 '-DANDROID_GDBSERVER=<(android_gdbserver)',
181 '-DANDROID_SDK=<(android_sdk)',
182 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
183 '-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
184 '-DANDROID_SDK_VERSION=<(android_sdk_version)',
185 '-DANDROID_TOOLCHAIN=<(android_toolchain)',
186 '-DCHROMIUM_SRC=<(ant_build_out)/../..',
187 '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
188 '-DPRODUCT_DIR=<(ant_build_out)',
190 '-DAPK_NAME=<(apk_name)',
191 '-DASSET_DIR=<(asset_location)',
192 '-DADDITIONAL_SRC_DIRS=>(additional_src_dirs)',
193 '-DGENERATED_SRC_DIRS=>(generated_src_dirs)',
194 '-DINPUT_JARS_PATHS=>(input_jars_paths)',
195 '-DJAR_NAME=<(jar_name)',
196 '-DOUT_DIR=<(ant_build_out)/<(_target_name)',
197 '-DRESOURCE_DIR=<(resource_dir)',
198 '-DADDITIONAL_R_TEXT_FILES=>(additional_R_text_files)',
199 '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
200 '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
201 '-DAPP_MANIFEST_VERSION_NAME=<(app_manifest_version_name)',
202 '-DAPP_MANIFEST_VERSION_CODE=<(app_manifest_version_code)',
203 '-DPROGUARD_FLAGS=>(proguard_flags)',
204 '-DPROGUARD_ENABLED=>(proguard_enabled)',
206 # Add list of inputs to the command line, so if inputs change
207 # (e.g. if a Java file is removed), the command will be re-run.
208 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
209 '-DTHIS_IS_IGNORED=>(_inputs)',
211 '-Dbasedir=<(java_in_dir)',
213 '<(DEPTH)/build/android/ant/chromium-apk.xml',
215 # Specify CONFIGURATION_NAME as the target for ant to build. The
216 # buildfile will then build the appropriate SDK tools target.
217 '<(CONFIGURATION_NAME)',