Commit 4346a217 authored by cjhopman@chromium.org's avatar cjhopman@chromium.org

Make android_apk template actually create an apk

This is essentially three steps, packaging resources, packaging code,
and then signing+zipaligning the apk.

The apk does not currently contain the native libraries.

Depends on http://crrev.com/386473002/

BUG=359249

Review URL: https://codereview.chromium.org/383613002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287729 0039d316-1c4b-4281-b951-d872f2087c98
parent 5e2cd3a6
...@@ -53,8 +53,7 @@ ...@@ -53,8 +53,7 @@
<!-- Intermediate files --> <!-- Intermediate files -->
<property name="resource.package.file.name" value="${RESOURCE_PACKAGED_APK_NAME}" /> <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="${DEX_FILE_PATH}" />
<property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
<!-- Macro that enables passing a variable list of external jar files <!-- Macro that enables passing a variable list of external jar files
to ApkBuilder. --> to ApkBuilder. -->
......
...@@ -15,6 +15,7 @@ Also, when a command fails, this script will re-run that ant command with the ...@@ -15,6 +15,7 @@ Also, when a command fails, this script will re-run that ant command with the
'-verbose' argument so that the failure is easier to debug. '-verbose' argument so that the failure is easier to debug.
""" """
import optparse
import sys import sys
import traceback import traceback
...@@ -22,14 +23,17 @@ from util import build_utils ...@@ -22,14 +23,17 @@ from util import build_utils
def main(argv): def main(argv):
option_parser = optparse.OptionParser()
build_utils.AddDepfileOption(option_parser)
options, args = option_parser.parse_args(argv[1:])
try: try:
args = argv[1:]
stdout = build_utils.CheckOutput(['ant'] + args) stdout = build_utils.CheckOutput(['ant'] + args)
except build_utils.CalledProcessError: except build_utils.CalledProcessError:
# It is very difficult to diagnose ant failures without the '-verbose' # It is very difficult to diagnose ant failures without the '-verbose'
# argument. So, when an ant command fails, re-run it with '-verbose' so that # argument. So, when an ant command fails, re-run it with '-verbose' so that
# the cause of the failure is easier to identify. # the cause of the failure is easier to identify.
verbose_args = ['-verbose'] + [a for a in argv[1:] if a != '-quiet'] verbose_args = ['-verbose'] + [a for a in args if a != '-quiet']
try: try:
stdout = build_utils.CheckOutput(['ant'] + verbose_args) stdout = build_utils.CheckOutput(['ant'] + verbose_args)
except build_utils.CalledProcessError: except build_utils.CalledProcessError:
...@@ -48,6 +52,14 @@ def main(argv): ...@@ -48,6 +52,14 @@ def main(argv):
break break
print line print line
if options.depfile:
assert '-buildfile' in args
ant_buildfile = args[args.index('-buildfile') + 1]
build_utils.WriteDepfile(
options.depfile,
[ant_buildfile] + build_utils.GetPythonDependencies())
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))
...@@ -70,6 +70,7 @@ def DropDataDescriptorsInApk(rezip_path, in_zip_file, out_zip_file): ...@@ -70,6 +70,7 @@ def DropDataDescriptorsInApk(rezip_path, in_zip_file, out_zip_file):
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--zipalign-path', help='Path to the zipalign tool.') parser.add_option('--zipalign-path', help='Path to the zipalign tool.')
parser.add_option('--rezip-path', help='Path to the rezip executable.') parser.add_option('--rezip-path', help='Path to the rezip executable.')
...@@ -125,6 +126,10 @@ def main(): ...@@ -125,6 +126,10 @@ def main():
UncompressLibAndPageAlignInApk( UncompressLibAndPageAlignInApk(
options.rezip_path, aligned_apk, options.final_apk_path) options.rezip_path, aligned_apk, options.final_apk_path)
if options.depfile:
build_utils.WriteDepfile(
options.depfile, build_utils.GetPythonDependencies())
if options.stamp: if options.stamp:
build_utils.Touch(options.stamp) build_utils.Touch(options.stamp)
......
...@@ -26,6 +26,7 @@ def ParseArgs(): ...@@ -26,6 +26,7 @@ def ParseArgs():
An options object as from optparse.OptionsParser.parse_args() An options object as from optparse.OptionsParser.parse_args()
""" """
parser = optparse.OptionParser() parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--android-sdk', help='path to the Android SDK folder') parser.add_option('--android-sdk', help='path to the Android SDK folder')
parser.add_option('--android-sdk-tools', parser.add_option('--android-sdk-tools',
help='path to the Android SDK build tools folder') help='path to the Android SDK build tools folder')
...@@ -128,6 +129,11 @@ def main(): ...@@ -128,6 +129,11 @@ def main():
build_utils.CheckOutput( build_utils.CheckOutput(
package_command, print_stdout=False, print_stderr=False) package_command, print_stdout=False, print_stderr=False)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -16,6 +16,10 @@ if (is_android) { ...@@ -16,6 +16,10 @@ if (is_android) {
# system, using the 'android' gyp backend. The WebView code is still built # system, using the 'android' gyp backend. The WebView code is still built
# when this is unset, but builds using the normal chromium build system. # when this is unset, but builds using the normal chromium build system.
is_android_webview_build = false is_android_webview_build = false
android_default_keystore_path = "//build/android/ant/chromium-debug.keystore"
android_default_keystore_name = "chromiumdebugkey"
android_default_keystore_password = "chromium"
} }
if (is_android_webview_build) { if (is_android_webview_build) {
...@@ -23,6 +27,7 @@ if (is_android) { ...@@ -23,6 +27,7 @@ if (is_android) {
"You must specify android_src for an Android WebView build.") "You must specify android_src for an Android WebView build.")
} }
# Host stuff ----------------------------------------------------------------- # Host stuff -----------------------------------------------------------------
# Defines the name the Android build gives to the current host CPU # Defines the name the Android build gives to the current host CPU
...@@ -62,6 +67,8 @@ if (is_android) { ...@@ -62,6 +67,8 @@ if (is_android) {
# Path to the SDK's android.jar # Path to the SDK's android.jar
android_sdk_jar = "$android_sdk/android.jar" android_sdk_jar = "$android_sdk/android.jar"
zipalign_path = "$android_sdk_build_tools/zipalign"
# Subdirectories inside android_ndk_root that contain the sysroot for the # Subdirectories inside android_ndk_root that contain the sysroot for the
# associated platform. # associated platform.
_android_api_level = 14 _android_api_level = 14
......
...@@ -145,6 +145,144 @@ template("dex") { ...@@ -145,6 +145,144 @@ template("dex") {
} }
} }
# Packages resources, assets, dex, and native libraries into an apk. Signs and
# zipaligns the apk.
template("create_apk") {
_android_manifest = invoker.android_manifest
_base_path = invoker.base_path
_final_apk_path = invoker.apk_path
_resources_zip = invoker.resources_zip
_dex_path = invoker.dex_path
_keystore_path = invoker.keystore_path
_keystore_name = invoker.keystore_name
_keystore_password = invoker.keystore_password
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}
_native_libs_dir = "//build/android/empty/res"
if (defined(invoker.native_libs_dir)) {
_native_libs_dir = invoker.native_libs_dir
}
_asset_location = "//build/android/empty/res"
if (defined(invoker.asset_location)) {
_asset_location = invoker.asset_location
}
_version_code = "0"
_version_name = "Developer Build"
_base_apk_path = _base_path + ".apk_intermediates"
_resource_packaged_apk_path = _base_apk_path + ".ap_"
_packaged_apk_path = _base_apk_path + ".unfinished.apk"
_configuration_name = "Release"
if (is_debug) {
_configuration_name = "Debug"
}
action("${target_name}__package_resources") {
deps = _deps
script = "//build/android/gyp/package_resources.py"
depfile = "${target_gen_dir}/${target_name}.d"
source_prereqs = [
_android_manifest,
_resources_zip,
]
outputs = [depfile, _resource_packaged_apk_path]
_rebased_resources_zips = [rebase_path(_resources_zip, root_build_dir)]
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--android-sdk", rebased_android_sdk,
"--android-sdk-tools", rebased_android_sdk_build_tools,
"--configuration-name=$_configuration_name",
"--android-manifest", rebase_path(_android_manifest, root_build_dir),
"--version-code", _version_code,
"--version-name", _version_name,
"--asset-dir", rebase_path(_asset_location, root_build_dir),
"--resource-zips=$_rebased_resources_zips",
"--apk-path", rebase_path(_resource_packaged_apk_path, root_build_dir),
]
}
action("${target_name}__package") {
script = "//build/android/gyp/ant.py"
_ant_script = "//build/android/ant/apk-package.xml"
depfile = "$target_gen_dir/$target_name.d"
source_prereqs = [
_dex_path,
_resource_packaged_apk_path,
_ant_script
]
outputs = [
depfile,
_packaged_apk_path,
]
_rebased_emma_jar = ""
_rebased_resource_packaged_apk_path = rebase_path(
_resource_packaged_apk_path, root_build_dir)
_rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir)
_rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
_rebased_dex_path = rebase_path(_dex_path, root_build_dir)
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--",
"-quiet",
"-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
"-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
"-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
"-DCONFIGURATION_NAME=$_configuration_name",
"-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
"-DOUT_DIR=",
"-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
"-DEMMA_INSTRUMENT=0",
"-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
"-DDEX_FILE_PATH=$_rebased_dex_path",
"-Dbasedir=.",
"-buildfile", rebase_path(_ant_script, root_build_dir)
]
}
action("${target_name}__finalize") {
script = "//build/android/gyp/finalize_apk.py"
depfile = "$target_gen_dir/$target_name.d"
sources = [_packaged_apk_path]
source_prereqs = [_keystore_path]
outputs = [depfile, _final_apk_path]
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--zipalign-path", rebase_path(zipalign_path, root_build_dir),
"--unsigned-apk-path", rebase_path(_packaged_apk_path, root_build_dir),
"--final-apk-path", rebase_path(_final_apk_path, root_build_dir),
"--key-path", rebase_path(_keystore_path, root_build_dir),
"--key-name", _keystore_name,
"--key-passwd", _keystore_password,
]
}
group(target_name) {
deps = [":${target_name}__finalize"]
}
}
# Compiles and jars a set of java files. # Compiles and jars a set of java files.
# #
# Outputs: # Outputs:
......
...@@ -506,9 +506,16 @@ template("android_apk") { ...@@ -506,9 +506,16 @@ template("android_apk") {
# Just mark these as used for now. # Just mark these as used for now.
assert(!defined(invoker.native_libs) assert(!defined(invoker.native_libs)
|| invoker.native_libs == [] || true) || invoker.native_libs == [] || true)
assert(!defined(invoker.final_apk_path)
|| invoker.final_apk_path == "" || true)
_keystore_path = android_default_keystore_path
_keystore_name = android_default_keystore_name
_keystore_password = android_default_keystore_password
if (defined(invoker.keystore_path)) {
_keystore_path = invoker.keystore_path
_keystore_name = invoker.keystore_name
_keystore_password = invoker.keystore_password
}
# TODO(cjhopman): Remove this once we correctly generate the real # TODO(cjhopman): Remove this once we correctly generate the real
# NativeLibraries.java # NativeLibraries.java
...@@ -558,6 +565,20 @@ template("android_apk") { ...@@ -558,6 +565,20 @@ template("android_apk") {
args = ["--inputs=@FileArg($dex_arg_key)"] args = ["--inputs=@FileArg($dex_arg_key)"]
} }
final_deps += [":${target_name}__create"]
create_apk("${target_name}__create") {
apk_path = invoker.final_apk_path
android_manifest = invoker.android_manifest
resources_zip = all_resources_zip_path
dex_path = final_dex_path
keystore_name = _keystore_name
keystore_path = _keystore_path
keystore_password = _keystore_password
# TODO: native libs
}
group(target_name) { group(target_name) {
deps = final_deps deps = final_deps
} }
......
...@@ -888,7 +888,9 @@ ...@@ -888,7 +888,9 @@
], ],
'action': [ 'action': [
'python', '<(DEPTH)/build/android/gyp/ant.py', 'python', '<(DEPTH)/build/android/gyp/ant.py',
'--',
'-quiet', '-quiet',
'-DDEX_FILE_PATH=<(intermediate_dir)/classes.dex',
'-DANDROID_SDK_ROOT=<(android_sdk_root)', '-DANDROID_SDK_ROOT=<(android_sdk_root)',
'-DANDROID_SDK_TOOLS=<(android_sdk_tools)', '-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
'-DRESOURCE_PACKAGED_APK_NAME=<(resource_packaged_apk_name)', '-DRESOURCE_PACKAGED_APK_NAME=<(resource_packaged_apk_name)',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment