22
33package io.deepmedia.tools.grease
44
5+ import com.android.build.api.component.analytics.AnalyticsEnabledLibraryVariant
6+ import com.android.build.api.component.analytics.AnalyticsEnabledVariant
57import com.android.build.api.variant.AndroidComponentsExtension
68import com.android.build.api.variant.Variant
79import com.android.build.api.variant.impl.getApiString
@@ -121,7 +123,7 @@ open class GreasePlugin : Plugin<Project> {
121123 val log = logger.child(" configureVariantManifest" )
122124 log.d { " Configuring variant output ${variant.name} ..." }
123125
124- val componentConfig = variant as ComponentCreationConfig
126+ val componentConfig = variant.componentCreationConfigOrThrow()
125127
126128 target.locateTask(componentConfig.computeTaskName(" process" , " Manifest" ))?.configure {
127129 val processManifestTask = this as ProcessLibraryManifest
@@ -222,7 +224,7 @@ open class GreasePlugin : Plugin<Project> {
222224 val log = logger.child(" configureVariantJniLibs" )
223225 log.d { " Configuring variant ${variant.name} ..." }
224226
225- val creationConfig = variant as ComponentCreationConfig
227+ val creationConfig = variant.componentCreationConfigOrThrow()
226228
227229 target.locateTask(creationConfig.computeTaskName(" copy" , " JniLibsProjectAndLocalJars" ))?.configure {
228230 val copyJniTask = this as LibraryJniLibsTask
@@ -319,7 +321,7 @@ open class GreasePlugin : Plugin<Project> {
319321
320322 val log = logger.child(" configureVariantResources" )
321323 log.d { " Configuring variant ${variant.name} ..." }
322- val creationConfig = variant as ComponentCreationConfig
324+ val creationConfig = variant.componentCreationConfigOrThrow()
323325
324326 target.locateTask(creationConfig.computeTaskName(" package" , " Resources" ))?.configure {
325327 this as MergeResources
@@ -389,7 +391,7 @@ open class GreasePlugin : Plugin<Project> {
389391 val log = logger.child(" configureVariantSources" )
390392 log.d { " Configuring variant ${variant.name} ..." }
391393
392- val creationConfig = variant as ComponentCreationConfig
394+ val creationConfig = variant.componentCreationConfigOrThrow()
393395
394396 val workdir = target.greaseBuildDir.get().dir(variant.name)
395397 val aarExtractWorkdir = workdir.dir(" extract" ).dir(" aar" )
@@ -567,7 +569,7 @@ open class GreasePlugin : Plugin<Project> {
567569 ) {
568570 val log = logger.child(" configureVariantAssets" )
569571 log.d { " Configuring variant ${variant.name} ..." }
570- val creationConfig = variant as ComponentCreationConfig
572+ val creationConfig = variant.componentCreationConfigOrThrow()
571573 creationConfig.taskContainer.mergeAssetsTask.configure {
572574 val extraAssets = configurations.artifactsOf(AndroidArtifacts .ArtifactType .ASSETS )
573575 dependsOn(extraAssets)
@@ -621,7 +623,7 @@ open class GreasePlugin : Plugin<Project> {
621623 ) {
622624 val log = logger.child(" configureVariantProguardFiles" )
623625 log.d { " Configuring variant ${variant.name} ..." }
624- val creationConfig = variant as ComponentCreationConfig
626+ val creationConfig = variant.componentCreationConfigOrThrow()
625627 target.locateTask(creationConfig.computeTaskName(" merge" , " ConsumerProguardFiles" ))?.configure {
626628 val mergeFileTask = this as MergeFileTask
627629 // UNFILTERED_PROGUARD_RULES, FILTERED_PROGUARD_RULES, AAPT_PROGUARD_RULES, ...
@@ -637,3 +639,11 @@ open class GreasePlugin : Plugin<Project> {
637639 }
638640 }
639641}
642+
643+ private fun Variant.componentCreationConfigOrThrow (): ComponentCreationConfig {
644+ return when (this ) {
645+ is ComponentCreationConfig -> this
646+ is AnalyticsEnabledVariant -> this .delegate.componentCreationConfigOrThrow()
647+ else -> error(" Could not find ComponentCreationConfig in $this ." )
648+ }
649+ }
0 commit comments