Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.tony19:apktool-lib:apktool-lib-1.4.4-5'
}
dependencies {
implementation("com.github.tony19:apktool-lib:apktool-lib-1.4.4-5")
}
<dependency>
<groupId>com.github.tony19</groupId>
<artifactId>apktool-lib</artifactId>
<version>apktool-lib-1.4.4-5</version>
</dependency>
libraryDependencies += "com.github.tony19" % "apktool-lib" % "apktool-lib-1.4.4-5"
:dependencies [[com.github.tony19/apktool-lib "apktool-lib-1.4.4-5"]]
<sup>v1.4.4-5</sup>
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.
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);
}
}
}
Gradle
dependencies {
compile 'com.github.tony19:apktool-lib:1.4.4-5'
}
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