Skip to content

Commit e67b599

Browse files
committed
Fix ComponentConfiguration crash
1 parent 41bf4a0 commit e67b599

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.iml
22
.gradle
33
**/local.properties
4-
/.idea/
4+
**/.idea/
55
.DS_Store
66
/build
77
/captures

grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package io.deepmedia.tools.grease
44

5+
import com.android.build.api.component.analytics.AnalyticsEnabledLibraryVariant
6+
import com.android.build.api.component.analytics.AnalyticsEnabledVariant
57
import com.android.build.api.variant.AndroidComponentsExtension
68
import com.android.build.api.variant.Variant
79
import 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+
}

grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private fun Project.createGrease(name: String, isTransitive: Boolean): Configura
8585
configurations.configureEach {
8686
val other = this
8787
if (other.name == nameOf(name, "compileClasspath")) {
88-
extendsFrom(configuration)
88+
other.extendsFrom(configuration)
8989
}
9090
}
9191
return configuration

tests/sample/build.gradle.kts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ dependencies {
6363
// Includes resource and some manifest changes
6464
implementation("androidx.lifecycle:lifecycle-runtime:2.8.4")
6565

66-
afterEvaluate {
67-
// Includes native libraries
68-
"greaseApi"("org.tensorflow:tensorflow-lite:2.3.0")
69-
// Manifest changes, layout resources
70-
"grease"("com.otaliastudios:cameraview:2.7.2")
71-
}
66+
// Includes native libraries
67+
greaseApi("org.tensorflow:tensorflow-lite:2.3.0")
68+
// Manifest changes, layout resources
69+
grease("com.otaliastudios:cameraview:2.7.2")
7270
}

0 commit comments

Comments
 (0)