Skip to content

Commit

Permalink
Fix "Could not get unknown property 'libraryVariants'" (#160)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
igorwojda authored and vanniktech committed Sep 3, 2019
1 parent df1c010 commit 9607c93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class GenerationPlugin implements Plugin<Project> {
subProject.android.jacoco.version = extension.jacocoVersion

Collection<BaseVariant> variants = []
if (isAndroidApplication(subProject)) {
if (isAndroidApplication(subProject) || isAndroidDynamicFeature(subProject)) {
variants = subProject.android.applicationVariants
} else if (isAndroidLibrary(subProject) || isAndroidFeature(subProject) || isAndroidDynamicFeature(subProject)) {
} else if (isAndroidLibrary(subProject) || isAndroidFeature(subProject)) {
// FeatureExtension extends LibraryExtension
variants = subProject.android.libraryVariants
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class ProjectHelper {
break
case ProjectType.ANDROID_APPLICATION:
case ProjectType.ANDROID_KOTLIN_APPLICATION:
case ProjectType.ANDROID_DYNAMIC_FEATURE:
project = builder.withName('android app').build()
def androidMock = new MockFor(AppExtension)
def buildTypesMock = ["debug", "release"].collect { bt ->
Expand All @@ -63,7 +64,6 @@ final class ProjectHelper {
break
case ProjectType.ANDROID_LIBRARY:
case ProjectType.ANDROID_FEATURE:
case ProjectType.ANDROID_DYNAMIC_FEATURE:
case ProjectType.ANDROID_KOTLIN_MULTIPLATFORM:
project = builder.withName('android library').build()
def androidMock = new MockFor(LibraryExtension)
Expand Down

0 comments on commit 9607c93

Please sign in to comment.