Index: build/android/gyp/deconstruct_apk.py |
diff --git a/build/android/gyp/deconstruct_apk.py b/build/android/gyp/deconstruct_apk.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fdb825dc0c36d13f890938d38d4ba193c8fea48 |
--- /dev/null |
+++ b/build/android/gyp/deconstruct_apk.py |
@@ -0,0 +1,61 @@ |
+# Copyright 2014 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. |
+ |
+import argparse |
+import os |
+import re |
+import shutil |
+import sys |
+ |
+from xml.dom import minidom |
+ |
+from util import build_utils |
+ |
+DECONSTRUCTED_APPLICATION = 'org.chromium.deconstructed.DeconstructedApplication' |
+ |
+def main(args): |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument('--apk') |
+ parser.add_argument('--new-apk') |
+ parser.add_argument('--remove-native') |
+ parser.add_argument('--remove-resources') |
+ parser.add_argument('--remove-java') |
+ options = parser.parse_args(args) |
+ |
+ with build_utils.TempDir() as temp_dir: |
+ files = build_utils.ExtractAll(options.apk, temp_dir) |
+ |
+ new_apk_dir = os.path.join(temp_dir, 'new_apk') |
+ native_dir = os.path.join(temp_dir, 'native') |
+ java_dir = os.path.join(temp_dir, 'java') |
+ resources_dir = os.path.join(temp_dir, 'resources') |
+ for f in files: |
+ new_dir = new_apk_dir |
+ if options.remove_native and f.startswith('lib/'): |
+ new_dir = native_dir |
+ if options.remove_java and f == 'classes.dex': |
+ new_dir = java_dir |
+ if options.remove_resources and (f == 'resources.arsc' or f.startswith('res/')): |
+ new_dir = resources_dir |
+ |
+ new_path = os.path.join(new_dir, f) |
+ new_dir = os.path.dirname(new_path) |
+ if not os.path.exists(new_dir): |
+ os.makedirs(os.path.dirname(new_path)) |
+ shutil.move(os.path.join(temp_dir, f), new_path) |
+ |
+ ReplaceManifestApplication(os.path.join(new_apk_dir, 'AndroidManifest.xml')) |
+ build_utils.ZipDir(options.new_apk, new_apk_dir) |
+ if options.remove_native: |
+ build_utils.ZipDir(options.remove_native, native_dir) |
+ if options.remove_java: |
+ build_utils.ZipDir(options.remove_java, java_dir) |
+ if options.remove_resources: |
+ build_utils.ZipDir(options.remove_resources, resources_dir) |
+ |
+ |
+ |
+if __name__ == "__main__": |
+ main(sys.argv[1:]) |
+ |