OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 """Creates an AndroidManifest.xml for an APK split. | 6 """Creates an AndroidManifest.xml for an APK split. |
7 | 7 |
8 Given the manifest file for the main APK, generates an AndroidManifest.xml with | 8 Given the manifest file for the main APK, generates an AndroidManifest.xml with |
9 the value required for a Split APK (package, versionCode, etc). | 9 the value required for a Split APK (package, versionCode, etc). |
10 """ | 10 """ |
11 | 11 |
12 import lxml.etree | |
13 import optparse | 12 import optparse |
| 13 import xml.etree.ElementTree |
14 | 14 |
15 from util import build_utils | 15 from util import build_utils |
16 | 16 |
17 MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?> | 17 MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?> |
18 <manifest | 18 <manifest |
19 xmlns:android="http://schemas.android.com/apk/res/android" | 19 xmlns:android="http://schemas.android.com/apk/res/android" |
20 package="%(package)s" | 20 package="%(package)s" |
21 split="%(split)s"> | 21 split="%(split)s"> |
22 <uses-sdk android:minSdkVersion="21" /> | 22 <uses-sdk android:minSdkVersion="21" /> |
23 <application android:hasCode="%(has_code)s"> | 23 <application android:hasCode="%(has_code)s"> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 Args: | 60 Args: |
61 main_manifest: the XML manifest of the main APK as a string | 61 main_manifest: the XML manifest of the main APK as a string |
62 split: the name of the split as a string | 62 split: the name of the split as a string |
63 has_code: whether this split APK will contain .dex files | 63 has_code: whether this split APK will contain .dex files |
64 | 64 |
65 Returns: | 65 Returns: |
66 The XML split manifest as a string | 66 The XML split manifest as a string |
67 """ | 67 """ |
68 | 68 |
69 doc = lxml.etree.fromstring(main_manifest) | 69 doc = xml.etree.ElementTree.fromstring(main_manifest) |
70 package = doc.xpath('/manifest/@package')[0] | 70 package = doc.get('package') |
71 | 71 |
72 return MANIFEST_TEMPLATE % { | 72 return MANIFEST_TEMPLATE % { |
73 'package': package, | 73 'package': package, |
74 'split': split.replace('-', '_'), | 74 'split': split.replace('-', '_'), |
75 'has_code': str(has_code).lower() | 75 'has_code': str(has_code).lower() |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 def main(): | 79 def main(): |
80 options = ParseArgs() | 80 options = ParseArgs() |
81 main_manifest = file(options.main_manifest).read() | 81 main_manifest = file(options.main_manifest).read() |
82 split_manifest = Build( | 82 split_manifest = Build( |
83 main_manifest, | 83 main_manifest, |
84 options.split, | 84 options.split, |
85 options.has_code) | 85 options.has_code) |
86 | 86 |
87 with file(options.out_manifest, 'w') as f: | 87 with file(options.out_manifest, 'w') as f: |
88 f.write(split_manifest) | 88 f.write(split_manifest) |
89 | 89 |
90 if options.depfile: | 90 if options.depfile: |
91 build_utils.WriteDepfile( | 91 build_utils.WriteDepfile( |
92 options.depfile, | 92 options.depfile, |
93 [options.main_manifest] + build_utils.GetPythonDependencies()) | 93 [options.main_manifest] + build_utils.GetPythonDependencies()) |
94 | 94 |
95 | 95 |
96 if __name__ == '__main__': | 96 if __name__ == '__main__': |
97 main() | 97 main() |
OLD | NEW |