From 9607c93303434cc74f6e98e3019deb01b6e4c53a Mon Sep 17 00:00:00 2001 From: Igor Wojda Date: Tue, 3 Sep 2019 08:52:49 +0100 Subject: [PATCH] Fix "Could not get unknown property 'libraryVariants'" (#160) * Fix "Could not get unknown property 'libraryVariants'" It looks like my prev dynamic-feature PR https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/pull/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 --- .../vanniktech/android/junit/jacoco/GenerationPlugin.groovy | 4 ++-- .../com/vanniktech/android/junit/jacoco/ProjectHelper.groovy | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy b/src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy index f69ff88..ec0a511 100644 --- a/src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy +++ b/src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy @@ -113,9 +113,9 @@ class GenerationPlugin implements Plugin { subProject.android.jacoco.version = extension.jacocoVersion Collection 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 { diff --git a/src/test/groovy/com/vanniktech/android/junit/jacoco/ProjectHelper.groovy b/src/test/groovy/com/vanniktech/android/junit/jacoco/ProjectHelper.groovy index f96b5de..cac5975 100644 --- a/src/test/groovy/com/vanniktech/android/junit/jacoco/ProjectHelper.groovy +++ b/src/test/groovy/com/vanniktech/android/junit/jacoco/ProjectHelper.groovy @@ -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 -> @@ -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)