Skip to content

Commit

Permalink
[build] Update APK merger to handle secondary abi.
Browse files Browse the repository at this point in the history
This allows the 32-bit build of the shared library to
overwrite the one built via the 64-bit build.

Bug: 908115, 893125
Change-Id: I0ede727cfced2dd5285f75594f08b8c3450e8a27
Reviewed-on: https://chromium-review.googlesource.com/c/1357312
Reviewed-by: Tao Bai <[email protected]>
Reviewed-by: agrieve <[email protected]>
Commit-Queue: Ben Mason <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#613296}(cherry picked from commit 6917b4e)
Reviewed-on: https://chromium-review.googlesource.com/c/1361294
Reviewed-by: Ben Mason <[email protected]>
Cr-Commit-Position: refs/branch-heads/3626@{#31}
Cr-Branched-From: d897fb1-refs/heads/master@{#612437}
  • Loading branch information
Ben Mason committed Dec 4, 2018
1 parent 3439e5a commit 29d5afc
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions android_webview/tools/apk_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
To use this script, you need to
1. Build 32-bit APK as usual.
2. Build 64-bit APK with GN variable build_apk_secondary_abi=false.
2. Build 64-bit APK with GN variable build_apk_secondary_abi=false OR true.
3. Use this script to merge 2 APKs.
"""
Expand Down Expand Up @@ -53,9 +53,10 @@ class ApkMergeFailure(Exception):
pass


def UnpackApk(file_name, dst):
def UnpackApk(file_name, dst, ignore_paths=()):
zippy = zipfile.ZipFile(file_name)
zippy.extractall(dst)
files_to_extract = [f for f in zippy.namelist() if f not in ignore_paths]
zippy.extractall(dst, files_to_extract)


def GetNonDirFiles(top, base_dir):
Expand Down Expand Up @@ -150,6 +151,15 @@ def AddDiffFiles(diff_files, tmp_dir_32, out_zip, expected_files,
compress=compress)


def GetTargetAbiPath(apk_path, shared_library):
with zipfile.ZipFile(apk_path) as z:
matches = [p for p in z.namelist() if p.endswith(shared_library)]
if len(matches) != 1:
raise ApkMergeFailure('Found multiple/no libs for %s: %s' % (
shared_library, matches))
return matches[0]


def GetSecondaryAbi(apk_zipfile, shared_library):
ret = ''
for name in apk_zipfile.namelist():
Expand Down Expand Up @@ -188,7 +198,10 @@ def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64):
expected_files[f] = not args.uncompress_shared_libraries

# need to unpack APKs to compare their contents
UnpackApk(args.apk_64bit, tmp_dir_64)
assets_path = 'base/assets' if args.bundle else 'assets'
exclude_files_64 = ['%s/snapshot_blob_32.bin' % assets_path,
GetTargetAbiPath(args.apk_32bit, args.shared_library)]
UnpackApk(args.apk_64bit, tmp_dir_64, exclude_files_64)
UnpackApk(args.apk_32bit, tmp_dir_32)

ignores = ['META-INF', 'AndroidManifest.xml']
Expand All @@ -197,6 +210,10 @@ def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64):
if args.debug:
# see http://crbug.com/648720
ignores += ['webview_licenses.notice']
if args.bundle:
# if merging a bundle we must ignore the bundle specific
# proto files as they will always be different.
ignores += ['BundleConfig.pb', 'native.pb', 'resources.pb']

dcmp = filecmp.dircmp(
tmp_dir_64,
Expand All @@ -210,7 +227,7 @@ def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64):
CheckFilesExpected(diff_files, expected_files, args.component_build)

with zipfile.ZipFile(tmp_apk, 'w') as out_zip:
exclude_patterns = ['META-INF/*']
exclude_patterns = ['META-INF/*'] + exclude_files_64

# If there are libraries for which we don't want the 32 bit versions, we
# should remove them here.
Expand Down Expand Up @@ -244,6 +261,7 @@ def main():
parser.add_argument('--page-align-shared-libraries', action='store_true',
help='Obsolete, but remains for backwards compatibility')
parser.add_argument('--uncompress-shared-libraries', action='store_true')
parser.add_argument('--bundle', action='store_true')
parser.add_argument('--debug', action='store_true')
# This option shall only used in debug build, see http://crbug.com/631494.
parser.add_argument('--ignore-classes-dex', action='store_true')
Expand Down

0 comments on commit 29d5afc

Please sign in to comment.