To solve my problem here: Applying JaCoCo to all Android Studio gradle modules, I applied the solution here. This works fine so far for modules with

plugins {
    id("com.android.library")
}

As soon as I add the required apply from: '../jacoco/modules.gradle' into a module labeled as a Java library

plugins {
    id("java-library")
}

I get a

Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'android' for project ':lib1' of type org.gradle.api.Project.

I would like to add the apply from to the java library, so that JaCoCo reports were generated for them as well. What am I missin here?

2

There are 2 best solutions below

0
On

I assume you have also applied the snippet from the “Improvements” section of the solution you have linked to your ../jacoco/modules.gradle file? In that case you could replace that snippet with the following:

project.afterEvaluate {
    if (project.pluginManager.hasPlugin('com.android.library')) {
        android.libraryVariants.all { variant ->
            tasks.create(…)
        }
    } else {
        tasks.create(…)
    }
}

If that doesn’t solve it, then I’d recommend to run the build with Gradle’s --stacktrace option. That should give you more details on where exactly the missing property was found.

Without more information on your exact build setup it’s hard to really say more.

0
On

For Cordova - some outdated packages cause it - see https://github.com/google/cordova-plugin-browsertab/issues/43 & https://github.com/apache/cordova-android/issues/821, such us cordova-plugin-browsertab.

There are multiple ways to solve this, it's even an example from Cordova docs.

That one working for me - add cdvMinSdkVersion=21 inside gradle.properties. Haven't tried the other ones, but as per cordova-plugin-browsertab#43 (comment), it should work at least with exporting as environmental variable.