enighma
02/22/2024, 12:46 AMChris Lee
02/22/2024, 2:01 AMenighma
02/22/2024, 2:46 AM<modulename>-<flavor>.apk
I just want the build date postfixed.
I guess I could create a gradle task that runs on compile and does what you do. I just imagine there's somewhere to add a suffix.gildor
02/22/2024, 3:13 AMgildor
02/22/2024, 3:22 AMgildor
02/22/2024, 3:22 AMgildor
02/22/2024, 3:30 AMgildor
02/22/2024, 3:35 AMgildor
02/22/2024, 3:37 AMIt's not recommended to simply rename the APKs that are generated by the default task because Studio expects specific names.
Having an API to rename things based on date/time would break Studio deployment as Studio would not know where to get these files. Based on this the API exposed by AGP allows you to copy them only.
Daniel B Duval
02/25/2024, 2:55 PMandroidComponents {
onVariants(selector().all(), { variant ->
def targetDirectory = "outputs/apk/"
def copy = tasks.register("copy${variant.getName().capitalize()}Apks", Copy) {
from { variant.artifacts.get(SingleArtifact.APK.INSTANCE) }
exclude "**/androidTest/**"
include "*.apk"
into project.layout.buildDirectory.file(targetDirectory)
}
afterEvaluate {
if (tasks.findByName(("create${variant.getName().capitalize()}AndroidTestApkListingFileRedirect"))) {
tasks.named("create${variant.getName().capitalize()}AndroidTestApkListingFileRedirect").configure({
it.dependsOn(copy)
})
}
tasks.named("create${variant.getName().capitalize()}ApkListingFileRedirect").configure({
it.dependsOn(copy)
})
tasks.withType(PackageApplication.class).named("package${variant.getName().capitalize()}").configure {
finalizedBy(copy)
copy.get().dependsOn(it)
}
}
})
}