Skip to content

Commit 9607c93

Browse files
igorwojdavanniktech
authored andcommitted
Fix "Could not get unknown property 'libraryVariants'" (#160)
* Fix "Could not get unknown property 'libraryVariants'" It looks like my prev dynamic-feature PR #158 requires some polishing. After applying it to a project I got the error: ``` FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':feature_album'. > Could not get unknown property 'libraryVariants' for object of type com.android.build.gradle.AppExtension. ``` It looks like dynamic feature behaves differently that od `com.adndroid.featute` and does not have `libraryVariants` properly (It is `AppExtension`, not a `FeatureExtension`). Looking at [AppExtension docs](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.AppExtension.html) I think we should retrieve variants from `applicationVariants` property. * fix test
1 parent df1c010 commit 9607c93

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ class GenerationPlugin implements Plugin<Project> {
113113
subProject.android.jacoco.version = extension.jacocoVersion
114114

115115
Collection<BaseVariant> variants = []
116-
if (isAndroidApplication(subProject)) {
116+
if (isAndroidApplication(subProject) || isAndroidDynamicFeature(subProject)) {
117117
variants = subProject.android.applicationVariants
118-
} else if (isAndroidLibrary(subProject) || isAndroidFeature(subProject) || isAndroidDynamicFeature(subProject)) {
118+
} else if (isAndroidLibrary(subProject) || isAndroidFeature(subProject)) {
119119
// FeatureExtension extends LibraryExtension
120120
variants = subProject.android.libraryVariants
121121
} else {

src/test/groovy/com/vanniktech/android/junit/jacoco/ProjectHelper.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ final class ProjectHelper {
3939
break
4040
case ProjectType.ANDROID_APPLICATION:
4141
case ProjectType.ANDROID_KOTLIN_APPLICATION:
42+
case ProjectType.ANDROID_DYNAMIC_FEATURE:
4243
project = builder.withName('android app').build()
4344
def androidMock = new MockFor(AppExtension)
4445
def buildTypesMock = ["debug", "release"].collect { bt ->
@@ -63,7 +64,6 @@ final class ProjectHelper {
6364
break
6465
case ProjectType.ANDROID_LIBRARY:
6566
case ProjectType.ANDROID_FEATURE:
66-
case ProjectType.ANDROID_DYNAMIC_FEATURE:
6767
case ProjectType.ANDROID_KOTLIN_MULTIPLATFORM:
6868
project = builder.withName('android library').build()
6969
def androidMock = new MockFor(LibraryExtension)

0 commit comments

Comments
 (0)