Move stub resources into its own module

Stop relying on internal AGP intermediate paths in the build directory.
Use standard AGP classes to achieve the same result
This commit is contained in:
topjohnwu
2026-04-08 05:29:57 +00:00
committed by John Wu
parent fb8e5b569e
commit 240b6db1cc
59 changed files with 70 additions and 64 deletions
+10 -7
View File
@@ -170,7 +170,7 @@ fun Project.setupCoreLib() {
it.addGeneratedSourceDirectory(syncResources, SyncWithDir::outputFolder)
}
val stubTask = tasks.getByPath(":stub:comment$variantCapped")
val stubTask = tasks.getByPath(":stub:transform${variantCapped}Apk")
val syncAssets = tasks.register("sync${variantCapped}Assets", SyncWithDir::class) {
outputFolder.set(layout.buildDirectory.dir("$variantName/assets"))
into(outputFolder)
@@ -261,20 +261,23 @@ fun Project.setupAppCommon() {
androidAppComponents {
onVariants { variant ->
val commentTask = tasks.register(
"comment${variant.name.replaceFirstChar { it.uppercase() }}",
AddCommentTask::class.java
"transform${variant.name.replaceFirstChar { it.uppercase() }}Apk",
TransformApkTask::class.java
)
val transformationRequest = variant.artifacts.use(commentTask)
.wiredWithDirectories(AddCommentTask::apkFolder, AddCommentTask::outFolder)
.wiredWithDirectories(TransformApkTask::apkFolder, TransformApkTask::outFolder)
.toTransformMany(SingleArtifact.APK)
val signingConfig = androidApp.buildTypes.getByName(variant.buildType!!).signingConfig
commentTask.configure {
this.transformationRequest = transformationRequest
this.signingConfig = signingConfig
this.comment = "version=${Config.version}\n" +
"versionCode=${Config.versionCode}\n" +
"stubVersion=${Config.stubVersion}\n"
this.outFolder.set(layout.buildDirectory.dir("outputs/apk/${variant.name}"))
// Always add a transformation to set comments on the APK
this.transformations.add {
it.eocdComment = ("version=${Config.version}\n" +
"versionCode=${Config.versionCode}\n" +
"stubVersion=${Config.stubVersion}\n").toByteArray()
}
}
}