Touch up manifest if there's no source code.
The new package manager behavior requires packages without source code to have an application element with hasCode attribute set to false in their manifest. With this change, Soong can now automatically insert one for codeless apps. Test: app_test.go, manifest_fixer_test.py Fixes: 124375490 Change-Id: Ied89a8d07c63805ab910859a4f7c45fc1c60bb73
This commit is contained in:
@@ -59,6 +59,9 @@ def parse_args():
|
||||
default=None, type=lambda x: (str(x).lower() == 'true'),
|
||||
help=('specify if the app wants to use embedded native libraries. Must not conflict '
|
||||
'if already declared in the manifest.'))
|
||||
parser.add_argument('--has-no-code', dest='has_no_code', action='store_true',
|
||||
help=('adds hasCode="false" attribute to application. Ignored if application elem '
|
||||
'already has a hasCode attribute.'))
|
||||
parser.add_argument('input', help='input AndroidManifest.xml file')
|
||||
parser.add_argument('output', help='output AndroidManifest.xml file')
|
||||
return parser.parse_args()
|
||||
@@ -245,6 +248,28 @@ def add_extract_native_libs(doc, extract_native_libs):
|
||||
(attr.value, value))
|
||||
|
||||
|
||||
def set_has_code_to_false(doc):
|
||||
manifest = parse_manifest(doc)
|
||||
elems = get_children_with_tag(manifest, 'application')
|
||||
application = elems[0] if len(elems) == 1 else None
|
||||
if len(elems) > 1:
|
||||
raise RuntimeError('found multiple <application> tags')
|
||||
elif not elems:
|
||||
application = doc.createElement('application')
|
||||
indent = get_indent(manifest.firstChild, 1)
|
||||
first = manifest.firstChild
|
||||
manifest.insertBefore(doc.createTextNode(indent), first)
|
||||
manifest.insertBefore(application, first)
|
||||
|
||||
attr = application.getAttributeNodeNS(android_ns, 'hasCode')
|
||||
if attr is not None:
|
||||
# Do nothing if the application already has a hasCode attribute.
|
||||
return
|
||||
attr = doc.createAttributeNS(android_ns, 'android:hasCode')
|
||||
attr.value = 'false'
|
||||
application.setAttributeNode(attr)
|
||||
|
||||
|
||||
def main():
|
||||
"""Program entry point."""
|
||||
try:
|
||||
@@ -269,6 +294,9 @@ def main():
|
||||
if args.use_embedded_dex:
|
||||
add_use_embedded_dex(doc)
|
||||
|
||||
if args.has_no_code:
|
||||
set_has_code_to_false(doc)
|
||||
|
||||
if args.extract_native_libs is not None:
|
||||
add_extract_native_libs(doc, args.extract_native_libs)
|
||||
|
||||
|
Reference in New Issue
Block a user