aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross2019-02-05 23:55:21 -0600
committerColin Cross2019-02-08 09:24:47 -0600
commite4246abd7f456eb4119f2cffc01bdfca852584b5 (patch)
treeda9d75703d09106d677b1d5b8976a6cdc601e6ce /scripts
parent129b9ceeb147099a62c46b4ff74670bb1670e34b (diff)
downloadplatform-build-soong-e4246abd7f456eb4119f2cffc01bdfca852584b5.tar.gz
platform-build-soong-e4246abd7f456eb4119f2cffc01bdfca852584b5.tar.xz
platform-build-soong-e4246abd7f456eb4119f2cffc01bdfca852584b5.zip
Make manifest and APK agree on uncompressed native libs
Only put uncompressed native libs in an APK if the min_sdk_version supports it (>= 23, Marshmallow), and set android:extractNativeLibs="false" in the AndroidManifest.xml so that the platform won't extract them anyways. Bug: 117618214 Test: m checkbuild Change-Id: I760017e48bf3c6b618aabde0982df45995765d48
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/manifest_fixer.py33
-rwxr-xr-xscripts/manifest_fixer_test.py43
2 files changed, 75 insertions, 1 deletions
diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py
index 917f55b4..83868e60 100755
--- a/scripts/manifest_fixer.py
+++ b/scripts/manifest_fixer.py
@@ -63,8 +63,12 @@ def parse_args():
63 help='manifest is for a package built against the platform') 63 help='manifest is for a package built against the platform')
64 parser.add_argument('--use-embedded-dex', dest='use_embedded_dex', action='store_true', 64 parser.add_argument('--use-embedded-dex', dest='use_embedded_dex', action='store_true',
65 help=('specify if the app wants to use embedded dex and avoid extracted,' 65 help=('specify if the app wants to use embedded dex and avoid extracted,'
66 'locally compiled code. Should not be conflict if already declared ' 66 'locally compiled code. Must not conflict if already declared '
67 'in the manifest.')) 67 'in the manifest.'))
68 parser.add_argument('--extract-native-libs', dest='extract_native_libs',
69 default=None, type=lambda x: (str(x).lower() == 'true'),
70 help=('specify if the app wants to use embedded native libraries. Must not conflict '
71 'if already declared in the manifest.'))
68 parser.add_argument('input', help='input AndroidManifest.xml file') 72 parser.add_argument('input', help='input AndroidManifest.xml file')
69 parser.add_argument('output', help='output AndroidManifest.xml file') 73 parser.add_argument('output', help='output AndroidManifest.xml file')
70 return parser.parse_args() 74 return parser.parse_args()
@@ -295,6 +299,30 @@ def add_use_embedded_dex(doc):
295 raise RuntimeError('existing attribute mismatches the option of --use-embedded-dex') 299 raise RuntimeError('existing attribute mismatches the option of --use-embedded-dex')
296 300
297 301
302def add_extract_native_libs(doc, extract_native_libs):
303 manifest = parse_manifest(doc)
304 elems = get_children_with_tag(manifest, 'application')
305 application = elems[0] if len(elems) == 1 else None
306 if len(elems) > 1:
307 raise RuntimeError('found multiple <application> tags')
308 elif not elems:
309 application = doc.createElement('application')
310 indent = get_indent(manifest.firstChild, 1)
311 first = manifest.firstChild
312 manifest.insertBefore(doc.createTextNode(indent), first)
313 manifest.insertBefore(application, first)
314
315 value = str(extract_native_libs).lower()
316 attr = application.getAttributeNodeNS(android_ns, 'extractNativeLibs')
317 if attr is None:
318 attr = doc.createAttributeNS(android_ns, 'android:extractNativeLibs')
319 attr.value = value
320 application.setAttributeNode(attr)
321 elif attr.value != value:
322 raise RuntimeError('existing attribute extractNativeLibs="%s" conflicts with --extract-native-libs="%s"' %
323 (attr.value, value))
324
325
298def write_xml(f, doc): 326def write_xml(f, doc):
299 f.write('<?xml version="1.0" encoding="utf-8"?>\n') 327 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
300 for node in doc.childNodes: 328 for node in doc.childNodes:
@@ -325,6 +353,9 @@ def main():
325 if args.use_embedded_dex: 353 if args.use_embedded_dex:
326 add_use_embedded_dex(doc) 354 add_use_embedded_dex(doc)
327 355
356 if args.extract_native_libs is not None:
357 add_extract_native_libs(doc, args.extract_native_libs)
358
328 with open(args.output, 'wb') as f: 359 with open(args.output, 'wb') as f:
329 write_xml(f, doc) 360 write_xml(f, doc)
330 361
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py
index 1d8de556..4ad9afaf 100755
--- a/scripts/manifest_fixer_test.py
+++ b/scripts/manifest_fixer_test.py
@@ -381,5 +381,48 @@ class UseEmbeddedDexTest(unittest.TestCase):
381 manifest_input = self.manifest_tmpl % self.use_embedded_dex('false') 381 manifest_input = self.manifest_tmpl % self.use_embedded_dex('false')
382 self.assertRaises(RuntimeError, self.run_test, manifest_input) 382 self.assertRaises(RuntimeError, self.run_test, manifest_input)
383 383
384
385class AddExtractNativeLibsTest(unittest.TestCase):
386 """Unit tests for add_extract_native_libs function."""
387
388 def run_test(self, input_manifest, value):
389 doc = minidom.parseString(input_manifest)
390 manifest_fixer.add_extract_native_libs(doc, value)
391 output = StringIO.StringIO()
392 manifest_fixer.write_xml(output, doc)
393 return output.getvalue()
394
395 manifest_tmpl = (
396 '<?xml version="1.0" encoding="utf-8"?>\n'
397 '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n'
398 ' <application%s/>\n'
399 '</manifest>\n')
400
401 def extract_native_libs(self, value):
402 return ' android:extractNativeLibs="%s"' % value
403
404 def test_set_true(self):
405 manifest_input = self.manifest_tmpl % ''
406 expected = self.manifest_tmpl % self.extract_native_libs('true')
407 output = self.run_test(manifest_input, True)
408 self.assertEqual(output, expected)
409
410 def test_set_false(self):
411 manifest_input = self.manifest_tmpl % ''
412 expected = self.manifest_tmpl % self.extract_native_libs('false')
413 output = self.run_test(manifest_input, False)
414 self.assertEqual(output, expected)
415
416 def test_match(self):
417 manifest_input = self.manifest_tmpl % self.extract_native_libs('true')
418 expected = manifest_input
419 output = self.run_test(manifest_input, True)
420 self.assertEqual(output, expected)
421
422 def test_conflict(self):
423 manifest_input = self.manifest_tmpl % self.extract_native_libs('true')
424 self.assertRaises(RuntimeError, self.run_test, manifest_input, False)
425
426
384if __name__ == '__main__': 427if __name__ == '__main__':
385 unittest.main() 428 unittest.main()