Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: build/android/gyp/finalize_apk.py

Issue 334413006: Add support for uncompress library in APK to the build system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update for Ross' review Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/gyp/finalize_apk.py
diff --git a/build/android/gyp/finalize_apk.py b/build/android/gyp/finalize_apk.py
index d64e10d0f57cba2a7b9185c2d58e53cd46751014..d0a8939c7ede9d9e2b28848a399e96bd1d2e6551 100755
--- a/build/android/gyp/finalize_apk.py
+++ b/build/android/gyp/finalize_apk.py
@@ -14,6 +14,16 @@ import tempfile
from util import build_utils
+def RenameLibInApk(rezip_path, in_zip_file, out_zip_file):
+ rename_cmd = [
+ rezip_path,
+ 'rename',
+ in_zip_file,
+ out_zip_file,
+ ]
+ build_utils.CheckOutput(rename_cmd)
+
+
def SignApk(key_path, key_name, key_passwd, unsigned_path, signed_path):
shutil.copy(unsigned_path, signed_path)
sign_cmd = [
@@ -38,10 +48,31 @@ def AlignApk(zipalign_path, unaligned_path, final_path):
build_utils.CheckOutput(align_cmd)
+def UncompressLibAndPageAlignInApk(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',
+ in_zip_file,
+ out_zip_file,
+ ]
+ build_utils.CheckOutput(rename_cmd)
+
+
def main():
parser = optparse.OptionParser()
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.')
parser.add_option('--final-apk-path',
help='Path to output signed and aligned APK.')
@@ -49,14 +80,49 @@ def main():
parser.add_option('--key-passwd', help='Keystore password')
parser.add_option('--key-name', help='Keystore name')
parser.add_option('--stamp', help='Path to touch on success.')
+ parser.add_option('--uncompress-lib', type='int',
+ help='If non-zero, build an APK with the library uncompressed.')
rmcilroy 2014/06/25 17:25:19 update help comment to mention libraries are renam
Anton 2014/06/26 09:45:43 Done.
options, _ = parser.parse_args()
- with tempfile.NamedTemporaryFile() as intermediate_file:
+ in_apk = options.unsigned_apk_path
rmcilroy 2014/06/25 17:25:19 current_apk_file_path
Anton 2014/06/26 09:45:43 Done.
+
+ with tempfile.NamedTemporaryFile() as intermediate_file, \
rmcilroy 2014/06/25 17:25:19 rename intermediate_file appropriately (signed_apk
Anton 2014/06/26 09:45:43 Done.
+ tempfile.NamedTemporaryFile() as apk_to_sign_tmp, \
+ tempfile.NamedTemporaryFile() as apk_without_descriptors_tmp, \
+ tempfile.NamedTemporaryFile() as aligned_apk_tmp:
+
+ if options.uncompress_lib:
+ # 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.
+ apk_to_sign = apk_to_sign_tmp.name
+ RenameLibInApk(options.rezip_path, in_apk, apk_to_sign)
+ in_apk = apk_to_sign
+
signed_apk_path = intermediate_file.name
SignApk(options.key_path, options.key_name, options.key_passwd,
- options.unsigned_apk_path, signed_apk_path)
- AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path)
+ in_apk, signed_apk_path)
+ in_apk = signed_apk_path
+
+ if options.uncompress_lib:
+ # 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, in_apk, apk_to_align)
+ in_apk = apk_to_align
+ aligned_apk = aligned_apk_tmp.name
+ else:
+ aligned_apk = options.final_apk_path
rmcilroy 2014/06/25 17:25:19 Do the temp name tracking one way throughout the f
Anton 2014/06/26 09:45:43 This is not the current_apk_file_path
+
+ # Align uncompress items to 4 bytes
+ AlignApk(options.zipalign_path, in_apk, aligned_apk)
rmcilroy 2014/06/25 17:25:19 you need to move the aligned_apk to options.final_
Anton 2014/06/26 09:45:44 This is what L117 is doing.
+
+ if options.uncompress_lib:
+ # Uncompress the library and make sure that it is page aligned.
+ UncompressLibAndPageAlignInApk(
+ options.rezip_path, aligned_apk, options.final_apk_path)
if options.stamp:
build_utils.Touch(options.stamp)
@@ -64,5 +130,3 @@ def main():
if __name__ == '__main__':
sys.exit(main())
-
-

Powered by Google App Engine
This is Rietveld 408576698