Chromium Code Reviews| Index: build/android/gyp/finalize_apk.py |
| diff --git a/build/android/gyp/finalize_apk.py b/build/android/gyp/finalize_apk.py |
| index e66eac67e263baf4be4953f7e3b4702b13249102..5ba09e2ea48d82e069a491a80f313a8bc4d2e0a9 100755 |
| --- a/build/android/gyp/finalize_apk.py |
| +++ b/build/android/gyp/finalize_apk.py |
| @@ -14,17 +14,33 @@ import tempfile |
| from util import build_utils |
| -def RenameLibInApk(rezip_path, in_zip_file, out_zip_file): |
| - rename_cmd = [ |
| - rezip_path, |
| - 'rename', |
| +def AddPageAlignment(prealign_path, in_zip_file, out_zip_file): |
| + prealign_cmd = [ |
| + 'java', |
| + '-classpath', |
| + prealign_path, |
| + 'PrealignApk', |
| + 'addalignment', |
| in_zip_file, |
| out_zip_file, |
| ] |
| - build_utils.CheckOutput(rename_cmd) |
| + build_utils.CheckOutput(prealign_cmd) |
| + |
| + |
| +def ReorderApk(prealign_path, in_zip_file, out_zip_file): |
| + prealign_cmd = [ |
| + 'java', |
| + '-classpath', |
| + prealign_path, |
| + 'PrealignApk', |
| + 'reorder', |
| + in_zip_file, |
| + out_zip_file, |
| + ] |
| + build_utils.CheckOutput(prealign_cmd) |
| -def SignApk(key_path, key_name, key_passwd, unsigned_path, signed_path): |
| +def JarSigner(key_path, key_name, key_passwd, unsigned_path, signed_path): |
| shutil.copy(unsigned_path, signed_path) |
| sign_cmd = [ |
| 'jarsigner', |
| @@ -48,20 +64,10 @@ def AlignApk(zipalign_path, unaligned_path, final_path): |
| build_utils.CheckOutput(align_cmd) |
| -def UncompressLibAndPageAlignInApk(rezip_path, in_zip_file, out_zip_file): |
| +def RenameAndUncompressLibInApk(rezip_path, in_zip_file, out_zip_file): |
| rename_cmd = [ |
| rezip_path, |
| - 'inflatealign', |
| - in_zip_file, |
| - out_zip_file, |
| - ] |
| - build_utils.CheckOutput(rename_cmd) |
| - |
| - |
| -def DropDataDescriptorsInApk(rezip_path, in_zip_file, out_zip_file): |
| - rename_cmd = [ |
| - rezip_path, |
| - 'dropdescriptors', |
| + 'renameinflate', |
| in_zip_file, |
| out_zip_file, |
| ] |
| @@ -72,6 +78,7 @@ def main(): |
| parser = optparse.OptionParser() |
| build_utils.AddDepfileOption(parser) |
| + parser.add_option('--prealign-path', help='Path to the prealign 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('--unsigned-apk-path', help='Path to input unsigned APK.') |
| @@ -90,41 +97,36 @@ def main(): |
| with tempfile.NamedTemporaryFile() as signed_apk_path_tmp, \ |
| tempfile.NamedTemporaryFile() as apk_to_sign_tmp, \ |
| - tempfile.NamedTemporaryFile() as apk_without_descriptors_tmp, \ |
| - tempfile.NamedTemporaryFile() as aligned_apk_tmp: |
| + tempfile.NamedTemporaryFile() as uncompress_lib_apk_tmp: |
| if options.load_library_from_zip_file: |
| # We alter the name of the library so that the Android Package Manager |
| # does not extract it into a separate file. This must be done before |
| - # signing, as the filename is part of the signed manifest. |
| + # signing, as the filename is part of the signed manifest. At the same |
| + # time we uncompress the library, which is necessary so that it can be |
| + # loaded directly from the APK. |
| + uncompress_lib_apk_path = uncompress_lib_apk_tmp.name |
| + RenameAndUncompressLibInApk( |
| + options.rezip_path, options.unsigned_apk_path, |
| + uncompress_lib_apk_path) |
| apk_to_sign = apk_to_sign_tmp.name |
| - RenameLibInApk(options.rezip_path, options.unsigned_apk_path, apk_to_sign) |
| + # Move the library to a page boundary by adding a page alignment file. |
| + AddPageAlignment( |
| + options.prealign_path, uncompress_lib_apk_path, apk_to_sign) |
| else: |
| apk_to_sign = options.unsigned_apk_path |
| signed_apk_path = signed_apk_path_tmp.name |
| - SignApk(options.key_path, options.key_name, options.key_passwd, |
| - apk_to_sign, signed_apk_path) |
| + JarSigner(options.key_path, options.key_name, options.key_passwd, |
| + apk_to_sign, signed_apk_path) |
| if options.load_library_from_zip_file: |
| - # Signing adds data descriptors to the APK. These are redundant |
| - # information. We remove them as otherwise they can cause a |
| - # miscalculation in the page alignment. |
| - apk_to_align = apk_without_descriptors_tmp.name |
| - DropDataDescriptorsInApk( |
| - options.rezip_path, signed_apk_path, apk_to_align) |
| - aligned_apk = aligned_apk_tmp.name |
| + # Reorder the contents of the APK. This re-establishes the canonical |
| + # order which means the library will be back at its page aligned location. |
| + ReorderApk(options.prealign_path, signed_apk_path, options.final_apk_path) |
|
rmcilroy
2014/09/29 11:38:32
Given that ReorderApk also aligns the APK, could y
Anton
2014/09/29 16:30:17
Done.
|
| else: |
| - apk_to_align = signed_apk_path |
| - aligned_apk = options.final_apk_path |
| - |
| - # Align uncompress items to 4 bytes |
| - AlignApk(options.zipalign_path, apk_to_align, aligned_apk) |
| - |
| - if options.load_library_from_zip_file: |
| - # Uncompress the library and make sure that it is page aligned. |
| - UncompressLibAndPageAlignInApk( |
| - options.rezip_path, aligned_apk, options.final_apk_path) |
| + # Align uncompress items to 4 bytes |
| + AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path) |
| if options.depfile: |
| build_utils.WriteDepfile( |