예제 #1
0
def _ProcessManifest(path, arsc_package_name, disable_isolated_processes):
    doc, manifest_node, app_node = resource_utils.ParseAndroidManifest(path)

    # Ensure the manifest package matches that of the apk's arsc package
    # So that resource references resolve correctly. The actual manifest
    # package name is set via --rename-manifest-package.
    manifest_node.set('package', arsc_package_name)

    # Pylint for some reason things app_node is an int.
    # pylint: disable=no-member
    real_app_class = app_node.get(_AddNamespace('name'),
                                  _DEFAULT_APPLICATION_CLASS)
    app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME)
    # pylint: enable=no-member
    _CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class)

    # Seems to be a bug in ElementTree, as doc.find() doesn't work here.
    instrumentation_nodes = doc.findall('instrumentation')
    assert len(instrumentation_nodes) <= 2, (
        'Need to update incremental install to support >2 <instrumentation> tags'
    )
    for i, instrumentation_node in enumerate(instrumentation_nodes):
        real_instrumentation_class = instrumentation_node.get(
            _AddNamespace('name'))
        instrumentation_node.set(_AddNamespace('name'),
                                 _INCREMENTAL_INSTRUMENTATION_CLASSES[i])
        _CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i],
                        real_instrumentation_class)

    ret = ElementTree.tostring(doc.getroot(), encoding='UTF-8')
    # Disable check for page-aligned native libraries.
    ret = ret.replace('extractNativeLibs="false"', 'extractNativeLibs="true"')
    if disable_isolated_processes:
        ret = ret.replace('isolatedProcess="true"', 'isolatedProcess="false"')
    return ret
예제 #2
0
def _FixManifest(options, temp_dir):
    """Fix the APK's AndroidManifest.xml.

  This adds any missing namespaces for 'android' and 'tools', and
  sets certains elements like 'platformBuildVersionCode' or
  'android:debuggable' depending on the content of |options|.

  Args:
    options: The command-line arguments tuple.
    temp_dir: A temporary directory where the fixed manifest will be written to.
  Returns:
    Tuple of:
     * Manifest path within |temp_dir|.
     * Original package_name (if different from arsc_package_name).
  """
    def maybe_extract_version(j):
        try:
            return resource_utils.ExtractBinaryManifestValues(
                options.aapt2_path, j)
        except build_utils.CalledProcessError:
            return None

    android_sdk_jars = [
        j for j in options.include_resources
        if os.path.basename(j) in ('android.jar', 'android_system.jar')
    ]
    extract_all = [maybe_extract_version(j) for j in android_sdk_jars]
    successful_extractions = [x for x in extract_all if x]
    if len(successful_extractions) == 0:
        raise Exception('Unable to find android SDK jar among candidates: %s' %
                        ', '.join(android_sdk_jars))
    elif len(successful_extractions) > 1:
        raise Exception(
            'Found multiple android SDK jars among candidates: %s' %
            ', '.join(android_sdk_jars))
    version_code, version_name = successful_extractions.pop()[:2]

    debug_manifest_path = os.path.join(temp_dir, 'AndroidManifest.xml')
    doc, manifest_node, app_node = resource_utils.ParseAndroidManifest(
        options.android_manifest)

    manifest_node.set('platformBuildVersionCode', version_code)
    manifest_node.set('platformBuildVersionName', version_name)

    orig_package = manifest_node.get('package')
    if options.arsc_package_name:
        manifest_node.set('package', options.arsc_package_name)

    if options.debuggable:
        app_node.set(
            '{%s}%s' % (resource_utils.ANDROID_NAMESPACE, 'debuggable'),
            'true')

    with open(debug_manifest_path, 'w') as debug_manifest:
        debug_manifest.write(
            ElementTree.tostring(doc.getroot(), encoding='UTF-8'))

    return debug_manifest_path, orig_package