Apktool/build.gradle.kts
Igor Eisberg b49e77087d
refactor: clean up external pull parser and introduce brut.j.xml (#3709)
* refactor: clean up external pull parser and introduce brut.j.xml

We have no need for an XML pull parser in the project,
it was only used for testing, which is now done with XPath.

The external xpp3 library from org.ogce is obsolete and has
the issue of including javax.xml.namespace.QName which conflicts
with the JRE implementation that exists for a very long time now.
This makes direct usages of QName produce very obscure NPEs that
took me hours to figure out. This patch will allow further
optimization that is WIP.
The external library was replaced by the basic xmlpull API.

The MXSerializer has been cleaned and the features used by apktool
have been integrated into the custom implementation, now part of
a separate module called brut.j.xml.
Writing has been optimized by buffering write operations, inspired
by KXmlSerializer used by Android itself.

A class XmlPullUtils also written that allows copying from a
XmlPullParser into a XmlSerializer with or without an EventHandler.
We use it for AndroidManifestPullStreamDecoder (with EventHandler,
to allow omitting the uses-sdk tag), and for ResXmlPullStreamDecoder
(direct copy, without EventHandler).

saveDocument in ResXmlPatcher was tweaked to output proper output -
a new line after declaration and a new line after root element's
end tag.

TL;DR mostly behind the scene refactor, no end user changes.
2024-10-15 06:54:03 -04:00

168 lines
4.9 KiB
Plaintext

import java.io.ByteArrayOutputStream
val version = "2.10.1"
val suffix = "SNAPSHOT"
// Strings embedded into the build.
var gitRevision by extra("")
var apktoolVersion by extra("")
defaultTasks("build", "shadowJar", "proguard")
// Functions
val gitDescribe: String? by lazy {
val stdout = ByteArrayOutputStream()
try {
rootProject.exec {
commandLine("git", "describe", "--tags")
standardOutput = stdout
}
stdout.toString().trim().replace("-g", "-")
} catch (e: Exception) {
null
}
}
val gitBranch: String? by lazy {
val stdout = ByteArrayOutputStream()
try {
rootProject.exec {
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
standardOutput = stdout
}
stdout.toString().trim()
} catch (e: Exception) {
null
}
}
if ("release" !in gradle.startParameter.taskNames) {
val hash = this.gitDescribe
if (hash == null) {
gitRevision = "dirty"
apktoolVersion = "$version-dirty"
project.logger.lifecycle("Building SNAPSHOT (no .git folder found)")
} else {
gitRevision = hash
apktoolVersion = "$hash-SNAPSHOT"
project.logger.lifecycle("Building SNAPSHOT ($gitBranch): $gitRevision")
}
} else {
gitRevision = ""
apktoolVersion = if (suffix.isNotEmpty()) "$version-$suffix" else version;
project.logger.lifecycle("Building RELEASE ($gitBranch): $apktoolVersion")
}
plugins {
`java-library`
`maven-publish`
signing
}
tasks.withType<JavaCompile> {
options.compilerArgs.add("-Xlint:-options")
options.compilerArgs.add("--release 8")
options.encoding = "UTF-8"
}
allprojects {
repositories {
mavenCentral()
google()
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "java-library")
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
val mavenProjects = arrayOf("brut.j.common", "brut.j.util", "brut.j.dir", "brut.j.xml", "apktool-lib", "apktool-cli")
if (project.name in mavenProjects) {
apply(plugin = "maven-publish")
apply(plugin = "signing")
java {
withJavadocJar()
withSourcesJar()
}
publishing {
repositories {
maven {
url = if (suffix.contains("SNAPSHOT")) {
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials {
username = (project.properties["ossrhUsername"] ?: "").toString()
password = (project.properties["ossrhPassword"] ?: "").toString()
}
}
}
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])
groupId = "org.apktool"
artifactId = project.name
version = apktoolVersion
pom {
name = "Apktool"
description = "A tool for reverse engineering Android apk files."
url = "https://apktool.org"
licenses {
license {
name = "The Apache License 2.0"
url = "https://opensource.org/licenses/Apache-2.0"
}
}
developers {
developer {
id = "iBotPeaches"
name = "Connor Tumbleson"
email = "connor.tumbleson@gmail.com"
}
developer {
id = "brutall"
name = "Ryszard Wiśniewski"
email = "brut.alll@gmail.com"
}
}
scm {
connection = "scm:git:git://github.com/iBotPeaches/Apktool.git"
developerConnection = "scm:git:git@github.com:iBotPeaches/Apktool.git"
url = "https://github.com/iBotPeaches/Apktool"
}
}
}
}
}
tasks.withType<Javadoc>() {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
signing {
sign(publishing.publications["mavenJava"])
}
}
}
task("release") {
// Used for official releases.
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}