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 # 'package_name': 'my_package',
14 # 'apk_name': 'MyPackage',
15 # 'java_in_dir': 'path/to/package/root',
16 # 'resource_dir': 'res',
18 # 'includes': ['path/to/this/gypi/file'],
21 # Note that this assumes that there's an ant buildfile <package_name>_apk.xml in
22 # java_in_dir. So, if you have package_name="content_shell" and
23 # java_in_dir="content/shell/android/java" you should have a directory structure
26 # content/shell/android/java/content_shell_apk.xml
27 # content/shell/android/java/src/org/chromium/base/Foo.java
28 # content/shell/android/java/src/org/chromium/base/Bar.java
31 # package_name - Used to name the intermediate output directory and in the
32 # names of some output files.
33 # apk_name - The final apk will be named <apk_name>.apk
34 # java_in_dir - The top-level java directory. The src should be in
36 # Optional/automatic variables:
37 # additional_input_paths - These paths will be included in the 'inputs' list to
38 # ensure that this target is rebuilt when one of these paths changes.
39 # additional_res_dirs - Additional directories containing Android resources.
40 # additional_res_packages - Package names of the R.java files corresponding to
41 # each directory in additional_res_dirs.
42 # additional_src_dirs - Additional directories with .java files to be compiled
43 # and included in the output of this target.
44 # asset_location - The directory where assets are located (default:
45 # <PRODUCT_DIR>/<package_name>/assets).
46 # generated_src_dirs - Same as additional_src_dirs except used for .java files
47 # that are generated at build time. This should be set automatically by a
48 # target's dependencies. The .java files in these directories are not
49 # included in the 'inputs' list (unlike additional_src_dirs).
50 # input_jars_paths - The path to jars to be included in the classpath. This
51 # should be filled automatically by depending on the appropriate targets.
52 # is_test_apk - Set to 1 if building a test apk. This prevents resources from
53 # dependencies from being re-included.
54 # native_libs_paths - The path to any native library to be included in this
55 # target. This should be a path in <(SHARED_LIB_DIR). A stripped copy of
56 # the library will be included in the apk and symbolic links to the
57 # unstripped copy will be added to <(android_product_out) to enable native
59 # resource_dir - The directory for resources.
60 # R_package - A custom Java package to generate the resource file R.java in.
61 # By default, the package given in AndroidManifest.xml will be used.
65 'asset_location%': '',
66 'additional_input_paths': [],
67 'input_jars_paths': [],
68 'additional_src_dirs': [],
69 'generated_src_dirs': [],
70 'app_manifest_version_name%': '<(android_app_version_name)',
71 'app_manifest_version_code%': '<(android_app_version_code)',
72 'proguard_enabled%': 'false',
73 'proguard_flags%': '',
74 'native_libs_paths': [],
75 'jar_name%': 'chromium_apk_<(package_name).jar',
78 'additional_res_dirs': [],
79 'additional_res_packages': [],
83 '<@(native_libs_paths)'
85 # Pass the jar path to the apk's "fake" jar target. This would be better as
86 # direct_dependent_settings, but a variable set by a direct_dependent_settings
87 # cannot be lifted in a dependent to all_dependent_settings.
88 'all_dependent_settings': {
90 'apk_output_jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
95 'rule_name': 'copy_and_strip_native_libraries',
98 'stripped_library_path': '<(PRODUCT_DIR)/<(package_name)/libs/<(android_app_abi)/<(RULE_INPUT_ROOT).so',
101 '<(stripped_library_path)',
103 # There is no way to do 2 actions for each source library in gyp. So to
104 # both strip the library and create the link in <(link_dir) a separate
105 # script is required.
107 '<(DEPTH)/build/android/prepare_library_for_apk',
109 '<(RULE_INPUT_PATH)',
110 '<(stripped_library_path)',
116 'action_name': 'ant_<(package_name)_apk',
117 'message': 'Building <(package_name) apk.',
119 '<(java_in_dir)/AndroidManifest.xml',
120 '<(DEPTH)/build/android/ant/chromium-apk.xml',
121 '<(DEPTH)/build/android/ant/common.xml',
122 '<(DEPTH)/build/android/ant/sdk-targets.xml',
123 # If there is a separate find for additional_src_dirs, it will find the
124 # wrong .java files when additional_src_dirs is empty.
125 '>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
126 '>@(input_jars_paths)',
127 '>@(native_libs_paths)',
128 '>@(additional_input_paths)',
131 ['resource_dir!=""', {
132 'inputs': ['<!@(find <(java_in_dir)/<(resource_dir) -name "*")']
134 ['is_test_apk == 1', {
136 'additional_res_dirs=': [],
137 'additional_res_packages=': [],
140 ['proguard_enabled == "true" and proguard_flags != ""', {
141 'inputs': ['<(java_in_dir)/<(proguard_flags)']
145 '<(PRODUCT_DIR)/apks/<(apk_name).apk',
149 '-DAPP_ABI=<(android_app_abi)',
150 '-DANDROID_GDBSERVER=<(android_gdbserver)',
151 '-DANDROID_SDK=<(android_sdk)',
152 '-DANDROID_SDK_ROOT=<(android_sdk_root)',
153 '-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
154 '-DANDROID_SDK_VERSION=<(android_sdk_version)',
155 '-DANDROID_TOOLCHAIN=<(android_toolchain)',
156 '-DCHROMIUM_SRC=<(ant_build_out)/../..',
157 '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)',
158 '-DPRODUCT_DIR=<(ant_build_out)',
160 '-DAPK_NAME=<(apk_name)',
161 '-DASSET_DIR=<(asset_location)',
162 '-DADDITIONAL_SRC_DIRS=>(additional_src_dirs)',
163 '-DGENERATED_SRC_DIRS=>(generated_src_dirs)',
164 '-DINPUT_JARS_PATHS=>(input_jars_paths)',
165 '-DJAR_NAME=<(jar_name)',
166 '-DPACKAGE_NAME=<(package_name)',
167 '-DRESOURCE_DIR=<(resource_dir)',
168 '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
169 '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
170 '-DAPP_MANIFEST_VERSION_NAME=<(app_manifest_version_name)',
171 '-DAPP_MANIFEST_VERSION_CODE=<(app_manifest_version_code)',
172 '-DPROGUARD_FLAGS=>(proguard_flags)',
173 '-DPROGUARD_ENABLED=>(proguard_enabled)',
175 '-Dbasedir=<(java_in_dir)',
177 '<(DEPTH)/build/android/ant/chromium-apk.xml',
179 # Specify CONFIGURATION_NAME as the target for ant to build. The
180 # buildfile will then build the appropriate SDK tools target.
181 '<(CONFIGURATION_NAME)',
186 ['R_package != ""', {
188 # We generate R.java in package R_package (in addition to the package
189 # listed in the AndroidManifest.xml, which is unavoidable).
190 'additional_res_dirs': ['<(DEPTH)/build/android/ant/empty/res'],
191 'additional_res_packages': ['<(R_package)'],