mirror of
https://github.com/lone-cloud/prism-android
synced 2026-06-03 19:54:44 -07:00
Allow overriding AAPT2
This commit is contained in:
parent
f49d4f9f2e
commit
8b3e265c56
2 changed files with 31 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import RunBundletoolTask.Companion.buildToolInfo
|
||||
import RunBundletoolTask.Companion.aapt2
|
||||
import org.gradle.kotlin.dsl.register
|
||||
|
||||
plugins {
|
||||
|
|
@ -80,27 +80,27 @@ dependencies {
|
|||
|
||||
tasks.register<RunBundletoolTask>("reproduceUniversal") {
|
||||
group = "build"
|
||||
description = "Generate universal .apks from .aab avec bundletool"
|
||||
description = "Generate universal .apks from .aab with bundletool"
|
||||
dependsOn("bundleRelease")
|
||||
aabFile = project.rootDir.resolve("app/build/outputs/bundle/release/app-release.aab")
|
||||
universalApks = project.rootDir.resolve("universal.apks")
|
||||
aapt2 = project.aapt2(androidComponents)
|
||||
signature.set(RunBundletoolTask.Signature.UnsignedOrDebug)
|
||||
buildToolInfo.set(androidComponents.buildToolInfo())
|
||||
}
|
||||
|
||||
tasks.register<RunBundletoolTask>("bundletoolBuildApks") {
|
||||
group = "build"
|
||||
description = "Generate default and universal .apks from .aab avec bundletool"
|
||||
description = "Generate default and universal .apks from .aab with bundletool"
|
||||
|
||||
val aabPath = System.getenv("AAB") ?: error("AAB not set")
|
||||
aabFile = project.rootDir.resolve(aabPath)
|
||||
universalApks = project.rootDir.resolve("universal.apks")
|
||||
defaultApks = project.rootDir.resolve("app.apks")
|
||||
aapt2 = project.aapt2(androidComponents)
|
||||
|
||||
val ks = System.getenv("KS") ?: error("KS not set")
|
||||
val ksPass = System.getenv("KS_PASS") ?: error("KS_PASS not set")
|
||||
val keyAlias = System.getenv("KEY_ALIAS") ?: error("KEY_ALIAS not set")
|
||||
|
||||
signature.set(RunBundletoolTask.Signature.Signed(ks, ksPass, keyAlias))
|
||||
buildToolInfo.set(androidComponents.buildToolInfo())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.android.tools.build.bundletool.commands.BuildApksCommand
|
|||
import com.android.tools.build.bundletool.model.Password
|
||||
import com.android.tools.build.bundletool.model.SigningConfiguration
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.InputFile
|
||||
|
|
@ -40,7 +41,7 @@ abstract class RunBundletoolTask : DefaultTask() {
|
|||
abstract val universalApks: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
abstract val buildToolInfo: Property<BuildToolInfo>
|
||||
abstract val aapt2: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
abstract val signature: Property<Signature>
|
||||
|
|
@ -48,10 +49,13 @@ abstract class RunBundletoolTask : DefaultTask() {
|
|||
@Suppress("NewApi")
|
||||
@TaskAction
|
||||
fun generateApks() {
|
||||
val aapt2Path = buildToolInfo.get().getPath(BuildToolInfo.PathId.AAPT2)
|
||||
?: error("aapt2 not found")
|
||||
val aapt2Path = aapt2.get().asFile.toPath()
|
||||
val aabPath = aabFile.get().asFile.toPath()
|
||||
|
||||
val aapt2Command = Aapt2Command.createFromExecutablePath(Paths.get(aapt2Path))
|
||||
println("➡ Compiling $aabPath")
|
||||
println("➡ Using $aapt2Path")
|
||||
|
||||
val aapt2Command = Aapt2Command.createFromExecutablePath(aapt2Path)
|
||||
val signature = signature.get()
|
||||
val signingConfig = if (signature is Signature.Signed) {
|
||||
SigningConfiguration.extractFromKeystore(
|
||||
|
|
@ -82,7 +86,7 @@ abstract class RunBundletoolTask : DefaultTask() {
|
|||
.build()
|
||||
.execute()
|
||||
|
||||
println("$outputFile generated")
|
||||
println("✅ $outputFile generated")
|
||||
}
|
||||
if (defaultApks.isPresent) {
|
||||
val outputFile = defaultApks.get().asFile.toPath()
|
||||
|
|
@ -101,23 +105,28 @@ abstract class RunBundletoolTask : DefaultTask() {
|
|||
.build()
|
||||
.execute()
|
||||
|
||||
println("$outputFile generated")
|
||||
println("✅ $outputFile generated")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Suppress("NewApi")
|
||||
fun ApplicationAndroidComponentsExtension.buildToolInfo(): BuildToolInfo {
|
||||
fun Project.aapt2(androidComponents: ApplicationAndroidComponentsExtension): java.io.File {
|
||||
val path = if (project.hasProperty("android.aapt2FromMavenOverride")) {
|
||||
project.property("android.aapt2FromMavenOverride") as String
|
||||
} else {
|
||||
val buildToolsVersion = SdkConstants.CURRENT_BUILD_TOOLS_VERSION
|
||||
val buildToolsDir = Paths.get(
|
||||
sdkComponents.sdkDirectory.get().toString(),
|
||||
androidComponents.sdkComponents.sdkDirectory.get().toString(),
|
||||
SdkConstants.FD_BUILD_TOOLS,
|
||||
SdkConstants.CURRENT_BUILD_TOOLS_VERSION
|
||||
)
|
||||
return BuildToolInfo.fromStandardDirectoryLayout(
|
||||
BuildToolInfo.fromStandardDirectoryLayout(
|
||||
Revision.parseRevision(buildToolsVersion),
|
||||
buildToolsDir
|
||||
)
|
||||
).getPath(BuildToolInfo.PathId.AAPT2)
|
||||
}
|
||||
return project.rootDir.resolve(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue