@ -29,7 +29,7 @@ import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskAction
import org.gradle. kotlin.dsl.configure
import org.gradle. configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.register
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.process.ExecOperations
import org.gradle.process.ExecOperations
@ -58,7 +58,7 @@ abstract class GenerateBadgingTask : DefaultTask() {
aapt2Executable . get ( ) . asFile . absolutePath ,
aapt2Executable . get ( ) . asFile . absolutePath ,
" dump " ,
" dump " ,
" badging " ,
" badging " ,
apk . get ( ) . asFile . absolutePath
apk . get ( ) . asFile . absolutePath ,
)
)
standardOutput = badging . asFile . get ( ) . outputStream ( )
standardOutput = badging . asFile . get ( ) . outputStream ( )
}
}
@ -86,12 +86,12 @@ abstract class CheckBadgingTask : DefaultTask() {
if (
if (
Files . mismatch (
Files . mismatch (
goldenBadging . get ( ) . asFile . toPath ( ) ,
goldenBadging . get ( ) . asFile . toPath ( ) ,
generatedBadging . get ( ) . asFile . toPath ( )
generatedBadging . get ( ) . asFile . toPath ( ) ,
) != - 1L
) != - 1L
) {
) {
throw GradleException (
throw GradleException (
" Generated badging is different from golden badging! " +
" Generated badging is different from golden badging! " +
" If this change is intended, run ./gradlew updateBadging "
" If this change is intended, run ./gradlew updateBadging " ,
)
)
}
}
}
}
@ -99,44 +99,47 @@ abstract class CheckBadgingTask : DefaultTask() {
fun Project . configureBadgingTasks (
fun Project . configureBadgingTasks (
baseExtension : BaseExtension ,
baseExtension : BaseExtension ,
componentsExtension : ApplicationAndroidComponentsExtension
componentsExtension : ApplicationAndroidComponentsExtension ,
) {
) {
// Registers a callback to be called, when a new variant is configured
// Registers a callback to be called, when a new variant is configured
componentsExtension . onVariants { variant ->
componentsExtension . onVariants { variant ->
// Registers a new task to verify the app bundle.
// Registers a new task to verify the app bundle.
val generateBadging = tasks . register < GenerateBadgingTask > ( " generate ${variant.name} Badging " ) {
val capitalizedVariantName = variant . name . capitalized ( )
apk . set (
val generateBadging =
variant . artifacts . get ( SingleArtifact . APK _FROM _BUNDLE )
tasks . register < GenerateBadgingTask > ( " generate ${capitalizedVariantName} Badging " ) {
)
apk . set (
aapt2Executable . set (
variant . artifacts . get ( SingleArtifact . APK _FROM _BUNDLE ) ,
File (
)
baseExtension . sdkDirectory ,
aapt2Executable . set (
" build-tools/ ${baseExtension.buildToolsVersion} /aapt2 "
File (
baseExtension . sdkDirectory ,
" build-tools/ ${baseExtension.buildToolsVersion} /aapt2 " ,
) ,
)
)
)
badging . set (
badging . set (
project . layout . buildDirectory . file (
project . layout . buildDirectory . file (
" outputs/apk_from_bundle/ ${variant.name} / ${variant.name} -badging.txt "
" outputs/apk_from_bundle/ ${variant.name} / ${variant.name} -badging.txt " ,
) ,
)
)
)
}
}
tasks . register < Copy > ( " update ${ variant.n ame}Badging " ) {
tasks . register < Copy > ( " update ${ capitalizedVariantN ame}Badging " ) {
from ( generateBadging . get ( ) . badging )
from ( generateBadging . get ( ) . badging )
into ( project . layout . projectDirectory )
into ( project . layout . projectDirectory )
}
}
val checkBadgingTaskName = " check ${ variant.n ame}Badging "
val checkBadgingTaskName = " check ${ capitalizedVariantN ame}Badging "
tasks . register < CheckBadgingTask > ( checkBadgingTaskName ) {
tasks . register < CheckBadgingTask > ( checkBadgingTaskName ) {
goldenBadging . set (
goldenBadging . set (
project . layout . projectDirectory . file ( " ${variant.name} -badging.txt " ) )
project . layout . projectDirectory . file ( " ${variant.name} -badging.txt " ) ,
)
generatedBadging . set (
generatedBadging . set (
generateBadging . get ( ) . badging
generateBadging . get ( ) . badging ,
)
)
output . set (
output . set (
project . layout . buildDirectory . dir ( " intermediates/ $checkBadgingTaskName " )
project . layout . buildDirectory . dir ( " intermediates/ $checkBadgingTaskName " ) ,
)
)
}
}
}
}