diff options
-rw-r--r-- | build/android/ant/apk-package-resources.xml | 113 | ||||
-rw-r--r-- | build/android/ant/apk-package.xml | 2 | ||||
-rwxr-xr-x | build/android/gyp/package_resources.py | 93 | ||||
-rw-r--r-- | build/java.gypi | 11 | ||||
-rw-r--r-- | build/java_apk.gypi | 86 |
5 files changed, 152 insertions, 153 deletions
diff --git a/build/android/ant/apk-package-resources.xml b/build/android/ant/apk-package-resources.xml deleted file mode 100644 index b2e1606..0000000 --- a/build/android/ant/apk-package-resources.xml +++ /dev/null @@ -1,113 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Copyright (C) 2005-2008 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<project default="-package-resources"> - <property name="out.dir" location="${OUT_DIR}" /> - <property name="out.absolute.dir" location="${out.dir}" /> - <property name="out.res.absolute.dir" location="${out.dir}/res" /> - - <!-- tools location --> - <property name="sdk.dir" location="${ANDROID_SDK_ROOT}"/> - <property name="project.target.android.jar" location="${ANDROID_SDK_JAR}" /> - <property name="android.sdk.tools.dir" location="${ANDROID_SDK_TOOLS}" /> - - <!-- jar file from where the tasks are loaded --> - <path id="android.antlibs"> - <pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" /> - </path> - - <!-- Custom tasks --> - <taskdef resource="anttasks.properties" classpathref="android.antlibs" /> - - <condition property="build.target" value="release" else="debug"> - <equals arg1="${CONFIGURATION_NAME}" arg2="Release" /> - </condition> - <condition property="build.is.packaging.debug" value="true" else="false"> - <equals arg1="${build.target}" arg2="debug" /> - </condition> - - <property name="resource.dir" value="${RESOURCE_DIR}"/> - <property name="resource.absolute.dir" location="${resource.dir}"/> - - <property name="asset.dir" value="${ASSET_DIR}" /> - <property name="asset.absolute.dir" location="${asset.dir}" /> - - <property name="aapt" location="${android.sdk.tools.dir}/aapt" /> - - <property name="version.code" value="${APP_MANIFEST_VERSION_CODE}"/> - <property name="version.name" value="${APP_MANIFEST_VERSION_NAME}"/> - - <!-- - Include additional resource folders in the apk, e.g. content/.../res. We - list the res folders in project.library.res.folder.path and the - corresponding java packages in project.library.packages, which must be - semicolon-delimited while ADDITIONAL_RES_PACKAGES is space-delimited, hence - the replacestring filterchain task. - --> - <path id="project.library.res.folder.path"> - <filelist files="${ADDITIONAL_RES_DIRS}"/> - </path> - <path id="project.library.bin.r.file.path"> - <filelist files="${ADDITIONAL_R_TEXT_FILES}"/> - </path> - - <loadresource property="project.library.packages"> - <propertyresource name="ADDITIONAL_RES_PACKAGES"/> - <filterchain> - <replacestring from=" " to=";"/> - </filterchain> - </loadresource> - <!-- Set to empty if not set by the loadresource above --> - <property name="project.library.packages" value=""/> - - <property name="build.packaging.nocrunch" value="true" /> - - <property name="manifest.file" value="${ANDROID_MANIFEST}" /> - <property name="manifest.abs.file" location="${manifest.file}" /> - - <!-- Intermediate files --> - <property name="resource.package.file.name" value="${APK_NAME}.ap_" /> - - <target name="-package-resources"> - <aapt - executable="${aapt}" - command="package" - versioncode="${version.code}" - versionname="${version.name}" - debug="${build.is.packaging.debug}" - manifest="${manifest.abs.file}" - assets="${asset.absolute.dir}" - androidjar="${project.target.android.jar}" - apkfolder="${out.absolute.dir}" - nocrunch="${build.packaging.nocrunch}" - resourcefilename="${resource.package.file.name}" - resourcefilter="" - libraryResFolderPathRefid="project.library.res.folder.path" - libraryPackagesRefid="project.library.packages" - libraryRFileRefid="project.library.bin.r.file.path" - previousBuildType="" - buildType="${build.target}" - ignoreAssets=""> - <res path="${out.res.absolute.dir}" /> - <res path="${resource.absolute.dir}" /> - <!-- <nocompress /> forces no compression on any files in assets or res/raw --> - <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw --> - </aapt> - - <touch file="${STAMP}" /> - </target> -</project> diff --git a/build/android/ant/apk-package.xml b/build/android/ant/apk-package.xml index 7cb6a96..e7df243 100644 --- a/build/android/ant/apk-package.xml +++ b/build/android/ant/apk-package.xml @@ -51,7 +51,7 @@ <property name="native.libs.absolute.dir" location="${NATIVE_LIBS_DIR}" /> <!-- Intermediate files --> - <property name="resource.package.file.name" value="${APK_NAME}.ap_" /> + <property name="resource.package.file.name" value="${RESOURCE_PACKAGED_APK_NAME}" /> <property name="dex.file.name" value="classes.dex" /> <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" /> diff --git a/build/android/gyp/package_resources.py b/build/android/gyp/package_resources.py new file mode 100755 index 0000000..cdb7bc61 --- /dev/null +++ b/build/android/gyp/package_resources.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# pylint: disable=C0301 +"""Package resources into an apk. + +See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tasks/src/main/java/com/android/ant/AaptExecTask.java +and +https://android.googlesource.com/platform/sdk/+/master/files/ant/build.xml +""" +# pylint: enable=C0301 + +import optparse +import os + +from util import build_utils + +def ParseArgs(): + """Parses command line options. + + Returns: + An options object as from optparse.OptionsParser.parse_args() + """ + parser = optparse.OptionParser() + parser.add_option('--android-sdk', help='path to the Android SDK folder') + parser.add_option('--android-sdk-tools', + help='path to the Android SDK build tools folder') + + parser.add_option('--configuration-name', + help='Gyp\'s configuration name (Debug or Release).') + + parser.add_option('--android-manifest', help='AndroidManifest.xml path') + parser.add_option('--version-code', help='Version code for apk.') + parser.add_option('--version-name', help='Version name for apk.') + parser.add_option('--resource-dirs', + help='directories containing resources to be packaged') + parser.add_option('--asset-dir', + help='directories containing assets to be packaged') + + parser.add_option('--apk-path', + help='Path to output (partial) apk.') + + (options, args) = parser.parse_args() + + if args: + parser.error('No positional arguments should be given.') + + # Check that required options have been provided. + required_options = ('android_sdk', 'android_sdk_tools', 'configuration_name', + 'android_manifest', 'version_code', 'version_name', + 'asset_dir', 'apk_path') + + build_utils.CheckOptions(options, parser, required=required_options) + + return options + + +def main(): + options = ParseArgs() + android_jar = os.path.join(options.android_sdk, 'android.jar') + aapt = os.path.join(options.android_sdk_tools, 'aapt') + + package_command = [aapt, + 'package', + '--version-code', options.version_code, + '--version-name', options.version_name, + '-M', options.android_manifest, + '--no-crunch', + '-f', + '--auto-add-overlay', + + '-I', android_jar, + '-F', options.apk_path, + ] + + if os.path.exists(options.asset_dir): + package_command += ['-A', options.asset_dir] + + for p in build_utils.ParseGypList(options.resource_dirs): + package_command += ['-S', p] + + if 'Debug' in options.configuration_name: + package_command += ['--debug-mode'] + + build_utils.CheckOutput( + package_command, print_stdout=False, print_stderr=False) + + +if __name__ == '__main__': + main() diff --git a/build/java.gypi b/build/java.gypi index ce778b1..d392206 100644 --- a/build/java.gypi +++ b/build/java.gypi @@ -140,9 +140,14 @@ # Dependent APKs include this target's resources via # additional_res_dirs, additional_res_packages, and # additional_R_text_files. - 'additional_res_dirs': ['<(res_crunched_dir)', - '<(res_v14_compatibility_dir)', - '<@(res_input_dirs)'], + 'additional_res_dirs': [ + # The order of these is important to ensure that the proper + # version (i.e. the crunched version) of resources takes + # precedence. + '<(res_crunched_dir)', + '<(res_v14_compatibility_dir)', + '<@(res_input_dirs)' + ], 'additional_res_packages': ['<(R_package)'], 'additional_R_text_files': ['<(R_text_file)'], }, diff --git a/build/java_apk.gypi b/build/java_apk.gypi index 66bf65d..c94959a 100644 --- a/build/java_apk.gypi +++ b/build/java_apk.gypi @@ -104,6 +104,9 @@ 'push_stamp': '<(intermediate_dir)/push.stamp', 'link_stamp': '<(intermediate_dir)/link.stamp', 'package_resources_stamp': '<(intermediate_dir)/package_resources.stamp', + 'crunch_output_dir': '<(intermediate_dir)/res', + 'resource_packaged_apk_name': '<(apk_name)-resources.ap_', + 'resource_packaged_apk_path': '<(intermediate_dir)/<(resource_packaged_apk_name)', 'unsigned_apk_path': '<(intermediate_dir)/<(apk_name)-unsigned.apk', 'final_apk_path%': '<(PRODUCT_DIR)/apks/<(apk_name).apk', 'incomplete_apk_path': '<(intermediate_dir)/<(apk_name)-incomplete.apk', @@ -476,7 +479,7 @@ '--proguard-file', '<(generated_proguard_file)', '--resource-dir', '<(resource_dir)', - '--crunch-output-dir', '<(intermediate_dir)/res', + '--crunch-output-dir', '<(crunch_output_dir)', '--R-dir', '<(intermediate_dir)/gen', @@ -646,18 +649,25 @@ 'includes': [ 'android/dex_action.gypi' ], }, { - 'action_name': 'ant package resources', - 'message': 'Packaging resources for <(_target_name) APK', - 'inputs': [ - '<(DEPTH)/build/android/ant/apk-package-resources.xml', - '<(DEPTH)/build/android/gyp/util/build_utils.py', - '<(DEPTH)/build/android/gyp/ant.py', - '<(android_manifest_path)', - '<(codegen_stamp)', - # TODO: This isn't always rerun correctly, http://crbug.com/351928 - - '>@(additional_input_paths)', - ], + 'action_name': 'package_resources', + 'message': 'packaging resources for <(_target_name)', + 'variables': { + 'extra_package_input_paths': [ + '>@(package_input_paths)', + '>@(additional_input_paths)', + '>@(resource_input_paths)' + ], + 'package_resource_dirs': [ + # <(crunch_output_dir) must come before <(resource_dir) so that + # the crunched files take precedence. + '<(crunch_output_dir)', + '<(resource_dir)', + '>@(additional_res_dirs)', + ], + # Write the inputs list to a file, so that its mtime is updated when + # the list of inputs changes. + 'inputs_list_file': '>|(apk_package.<(_target_name).gypcmd >@(extra_package_input_paths))', + }, 'conditions': [ ['is_test_apk == 1', { 'variables': { @@ -666,33 +676,36 @@ } }], ], + 'inputs': [ + # TODO: This isn't always rerun correctly, http://crbug.com/351928 + '<(DEPTH)/build/android/gyp/util/build_utils.py', + '<(DEPTH)/build/android/gyp/package_resources.py', + '<(android_manifest_path)', + + '<(codegen_stamp)', + + '>@(extra_package_input_paths)', + '>(inputs_list_file)', + ], 'outputs': [ - '<(package_resources_stamp)', + '<(resource_packaged_apk_path)', ], 'action': [ - 'python', '<(DEPTH)/build/android/gyp/ant.py', - '-quiet', - '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)', - '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)', - '-DADDITIONAL_R_TEXT_FILES=>(additional_R_text_files)', - '-DANDROID_MANIFEST=<(android_manifest_path)', - '-DANDROID_SDK_JAR=<(android_sdk_jar)', - '-DANDROID_SDK_ROOT=<(android_sdk_root)', - '-DANDROID_SDK_TOOLS=<(android_sdk_tools)', - '-DAPK_NAME=<(apk_name)', - '-DAPP_MANIFEST_VERSION_CODE=<(app_manifest_version_code)', - '-DAPP_MANIFEST_VERSION_NAME=<(app_manifest_version_name)', - '-DASSET_DIR=<(asset_location)', - '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)', - '-DOUT_DIR=<(intermediate_dir)', - '-DRESOURCE_DIR=<(resource_dir)', + 'python', '<(DEPTH)/build/android/gyp/package_resources.py', + '--android-sdk', '<(android_sdk)', + '--android-sdk-tools', '<(android_sdk_tools)', - '-DSTAMP=<(package_resources_stamp)', + '--configuration-name', '<(CONFIGURATION_NAME)', - '-Dbasedir=.', - '-buildfile', - '<(DEPTH)/build/android/ant/apk-package-resources.xml', - ] + '--android-manifest', '<(android_manifest_path)', + '--version-code', '<(app_manifest_version_code)', + '--version-name', '<(app_manifest_version_name)', + + '--asset-dir', '<(asset_location)', + '--resource-dirs', '>(package_resource_dirs)', + + '--apk-path', '<(resource_packaged_apk_path)', + ], }, { 'action_name': 'ant_package_<(_target_name)', @@ -709,7 +722,7 @@ '<(dex_path)', '<(codegen_stamp)', '<(obfuscate_stamp)', - '<(package_resources_stamp)', + '<(resource_packaged_apk_path)', '>@(package_input_paths)', '>(inputs_list_file)', ], @@ -721,6 +734,7 @@ '-quiet', '-DANDROID_SDK_ROOT=<(android_sdk_root)', '-DANDROID_SDK_TOOLS=<(android_sdk_tools)', + '-DRESOURCE_PACKAGED_APK_NAME=<(resource_packaged_apk_name)', '-DAPK_NAME=<(apk_name)', '-DCONFIGURATION_NAME=<(CONFIGURATION_NAME)', '-DNATIVE_LIBS_DIR=<(apk_package_native_libs_dir)', |