Skip to content

Commit

Permalink
chore: DexJar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Jun 3, 2024
1 parent 9bb16f4 commit 1fbbf53
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/main/kotlin/com/xpdustry/toxopid/task/DexJar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ public open class DexJar : DefaultTask() {
public val output: RegularFileProperty = project.objects.fileProperty()

/**
* The minimum sdk version to target. **Only change if you know what you are doing.**
* The minimum sdk version to target.
*
* **Only change if you know what you are doing.**
*/
@get:Input
public val minSdkVersion: Property<String> = project.objects.property()
public val minSdkVersion: Property<Int> = project.objects.property()

/**
* The classpath of the [source] jar file.
Expand All @@ -73,7 +75,7 @@ public open class DexJar : DefaultTask() {
public val classpath: ConfigurableFileCollection = project.objects.fileCollection()

init {
minSdkVersion.convention("14")
minSdkVersion.convention(14)
output.convention { temporaryDir.resolve("dexed.jar") }
}

Expand All @@ -96,30 +98,31 @@ public open class DexJar : DefaultTask() {
)
}

val root = Path(sdk)
val (platform, version) =
root.resolve("platforms").listDirectoryEntries()
Path(sdk).resolve("platforms").listDirectoryEntries()
.map { it to it.fileName.toString().removePrefix("android-").toInt() }
.maxByOrNull { it.second }
?: error("No Android SDK found")

logger.info("Using Android SDK at {}", version)

val arguments = mutableListOf<String>()
arguments.add("--lib")
arguments.add(platform.resolve("android.jar").absolutePathString())
classpath.map { it.toPath().absolutePathString() }.forEach {
arguments.add("--classpath")
arguments.add(it)
}
arguments.add("--min-api")
arguments.add(minSdkVersion.get())
arguments.add("--output")
arguments.add(output.get().asFile.absolutePath)
arguments.add(source.get().asFile.absolutePath)
val arguments =
buildList<String> {
add("--lib")
add(platform.resolve("android.jar").absolutePathString())
classpath.forEach {
add("--classpath")
add(it.toPath().absolutePathString())
}
add("--min-api")
add(minSdkVersion.get().toString())
add("--output")
add(output.get().asFile.absolutePath)
add(source.get().asFile.absolutePath)
}

val d8 =
root
Path(sdk)
.resolve("build-tools")
.listDirectoryEntries()
.filter { it.fileName.toString().startsWith(version.toString()) }
Expand Down

0 comments on commit 1fbbf53

Please sign in to comment.