Skip to content
This repository has been archived by the owner on Aug 7, 2018. It is now read-only.
/ apktool-lib Public archive
forked from broo2s/brut.apktool

A library for decoding XML resources (such as the Android manifest) from an APK

License

Notifications You must be signed in to change notification settings

tony19/apktool-lib

 
 

Repository files navigation

apktool-lib CircleCI branch

v1.4.4-5

Overview

This library decodes a given precompiled XML resource (such as AndroidManifest.xml) from an APK without requiring an Android application context.

Normally, precompiled (as opposed to raw) XML can be accessed from an Android application using AssetManager.openXmlResourceParser(). In order to get an instance of AssetManager, the caller must have access to the Android application context, which is normally unavailable for libraries. A possible workaround is to pass the context (e.g., via the consumer's constructor) to libraries that need context-specific classes, but that might be infeasible or undesirable in some applications, including ones that need access to the precompiled XML before the context is initialized. apktool-lib enables libraries to read precompiled XML without an application context or the Android AssetManager.

This is based on the APK Tool project.

Usage

Parse XML events from AXmlResourceParser in a loop, as in the following code example:

import brut.androlib.res.decoder.AXmlResourceParser;

//...

// called from a library, used by an Android application
public void readManifest() {
  InputStream manifestStream = getClassLoader().getResourceAsStream("AndroidManifest.xml");
  parseXmlStream(manifestStream);
}

public void parseXmlStream(InputStream stream) {
  AXmlResourceParser xpp = new AXmlResourceParser(stream);

  int eventType = -1;
  while ((eventType = xpp.next()) > -1) {
    if (XmlPullParser.START_DOCUMENT == eventType) {
      startDocument(xpp);
    } else if (XmlPullParser.END_DOCUMENT == eventType) {
      endDocument();
      break;
    } else if (XmlPullParser.START_TAG == eventType) {
      startElement(xpp);
    } else if (XmlPullParser.END_TAG == eventType) {
      endElement(xpp);
    } else if (XmlPullParser.TEXT == eventType) {
      characters(xpp);
    }
  }
}

Download

Gradle

dependencies {
  compile 'com.github.tony19:apktool-lib:1.4.4-5'
}

Build

Use these commands to create the AAR:

git clone git://github.com/tony19/apktool-lib.git
cd apktool-lib
scripts/makejar.sh

The file is output to: ./build/apktool-lib-1.4.4-5-debug.aar

License

Apache License 2.0

About

A library for decoding XML resources (such as the Android manifest) from an APK

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 92.9%
  • Shell 7.1%