Fix java handler. The java handler expects a Mojo-Class entry in the manifest of the application. The latest dx tool strip the manifest to its bare minimum and removed everything we added. This change the build system to add the entry to the manifest after running dx. R=blundell@chromium.org Review URL: https://codereview.chromium.org/1126393005
diff --git a/services/android/add_manifest_entry.py b/services/android/add_manifest_entry.py new file mode 100755 index 0000000..a00052e --- /dev/null +++ b/services/android/add_manifest_entry.py
@@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 2015 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. + +"""Add an entry into the manifest file of a jar file.""" + +import optparse +import os +import os.path +import sys +import shutil +import tempfile +import zipfile + +def AddKey(input_jar, output, key, value): + working_dir = tempfile.mkdtemp() + extracted_dir = os.path.join(working_dir, 'extracted') + try: + with zipfile.ZipFile(input_jar) as zf: + zf.extractall(extracted_dir) + manifest_file = os.path.join(extracted_dir, 'META-INF', 'MANIFEST.MF') + manifest_content = '' + if os.path.isfile(manifest_file): + with open(manifest_file, 'r') as f: + manifest_content = f.read().strip() + if len(manifest_content): + manifest_content += '\n' + os.unlink(manifest_file) + manifest_content += '%s: %s\n' % (key, value) + with open(manifest_file, 'w') as f: + f.write(manifest_content) + shutil.make_archive(os.path.join(working_dir, 'output'), 'zip', + extracted_dir, '.') + shutil.move(os.path.join(working_dir, 'output.zip'), output) + finally: + shutil.rmtree(working_dir) + + +def main(): + parser = optparse.OptionParser() + + parser.add_option('--input', help='Name of the input jar.') + parser.add_option('--output', help='Name of the output jar.') + parser.add_option('--key', help='Name of the key to add to the manifest.') + parser.add_option('--value', help='Name of the value to add to the manifest.') + + options, _ = parser.parse_args() + AddKey(options.input, options.output, options.key, options.value) + + +if __name__ == '__main__': + sys.exit(main())
diff --git a/services/android/rules.gni b/services/android/rules.gni index 9fe4089..350b421 100644 --- a/services/android/rules.gni +++ b/services/android/rules.gni
@@ -5,13 +5,18 @@ import("//build/config/android/rules.gni") import("//mojo/public/mojo_application.gni") +servicess_android_path = get_path_info(".", "abspath") + template("mojo_android_java_application") { assert(defined(invoker.mojo_main)) dex_output_path = "$target_out_dir/${target_name}.dex.jar" + dex_with_manifest_output_path = + "$target_out_dir/${target_name}_with_manifest.dex.jar" android_lib_name = "__${target_name}_lib" android_standalone_name = "__${target_name}_standalone" + android_with_manifest_name = "__${target_name}_with_manifest" all_deps = [ "//mojo/public/java:bindings", @@ -24,8 +29,6 @@ android_library(android_lib_name) { java_files = invoker.sources - manifest_entries = [ "Mojo-Class:" + invoker.mojo_main ] - deps = all_deps } @@ -38,6 +41,30 @@ excluded_jars = [ "${system_gen_dir}/system.dex.jar" ] } + action(android_with_manifest_name) { + script = "${servicess_android_path}/add_manifest_entry.py" + + input = dex_output_path + inputs = [ + input, + ] + + output = dex_with_manifest_output_path + outputs = [ + output, + ] + + rebase_input = rebase_path(input) + rebase_output = rebase_path(output) + mojo_main = invoker.mojo_main + args = [ + "--input=$rebase_input", + "--output=$rebase_output", + "--key=Mojo-Class", + "--value=$mojo_main", + ] + } + if (defined(invoker.output_name)) { mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" } else { @@ -47,7 +74,7 @@ action(target_name) { script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) - input = dex_output_path + input = dex_with_manifest_output_path inputs = [ input, ]