Skip to content

'variantName' property has null with Android Gradle Library Plugin for KMP #772

Closed
MobileByteLabs/worker-kmp
#48

Description

@xVemu

Describe the bug
I have gradle module with Android Gradle Library Plugin for KMP.
I've configured hostTests (aka unit tests).
I tried to apply kover plugin, but got the following error.

It's weird, because in afterEvaluate block variantName is not null

afterEvaluate {
    val task = tasks.withType<AndroidUnitTest>().single()

    task.variantName // it's not null
}

Errors

Stacktrace
Caused by: kotlinx.kover.gradle.plugin.commons.KoverCriticalException: Kover error: Non-nullable 'variantName' property has `null` value in dynamic bean over 'task ':components:testAndroidHostTest''
Please create an issue in Kover Gradle Plugin repository: https://github.com/Kotlin/kotlinx-kover/issues
	at kotlinx.kover.gradle.plugin.util.DynamicBean.value(DynamicBean.kt:38)
	at kotlinx.kover.gradle.plugin.locators.KotlinMultiPlatformLocatorKt$locateAndroidLibrary$tests$1.isSatisfiedBy(KotlinMultiPlatformLocator.kt:94)
	at kotlinx.kover.gradle.plugin.locators.KotlinMultiPlatformLocatorKt$locateAndroidLibrary$tests$1.isSatisfiedBy(KotlinMultiPlatformLocator.kt:93)
	at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$1.lambda$isSatisfiedBy$0(DefaultCollectionCallbackActionDecorator.java:62)
	at org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication.reapply(DefaultUserCodeApplicationContext.java:110)
	at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$1.isSatisfiedBy(DefaultCollectionCallbackActionDecorator.java:62)
	at org.gradle.api.internal.collections.CollectionFilter.filter(CollectionFilter.java:49)
	at org.gradle.api.internal.collections.CollectionFilter$1.execute(CollectionFilter.java:60)
	at org.gradle.api.internal.collections.CollectionFilter$1.execute(CollectionFilter.java:62)
	at org.gradle.internal.ImmutableActionSet$SetWithManyActions.execute(ImmutableActionSet.java:329)
	at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:280)
	at org.gradle.api.internal.DefaultNamedDomainObjectCollection.doAdd(DefaultNamedDomainObjectCollection.java:125)
	at org.gradle.api.internal.DefaultNamedDomainObjectCollection$AbstractDomainObjectCreatingProvider.tryCreate(DefaultNamedDomainObjectCollection.java:1008)
	... 219 more

Expected behavior
Gradle project should successfully sync.

Reproducer

build.gradle.kts

androidLibrary {
    namespace = "..."
    compileSdk = libs.versions.android.sdk.compile.get().toInt()
    minSdk = libs.versions.android.sdk.min.get().toInt()

    androidResources.enable = true

    withHostTest {
        isIncludeAndroidResources = true
    }
} 

Environment

Activity

  1. added
    Bug
    S: untriaged
    on Nov 7, 2025
  2. Siedlerchr commented on Dec 17, 2025

    @Siedlerchr

    Ran into the same issue, happens as soon I add withHostTest {}

  3. G00fY2 commented on Jan 15, 2026

    @G00fY2

    I there any (temporary) workaround for this?

    Edit: Adding this seems to fix the issue for now:

        tasks.withType<Test>().configureEach {
            (this as? AndroidUnitTest)?.variantName = "android"
        }
  4. added
    S: waiting for clarification
    and removed
    S: untriaged
    on Jan 15, 2026
  5. shanshin commented on Jan 15, 2026

    @shanshin
    Collaborator

    Hi, could you please provide a small reproducer project?
    This will help to better understand the source of the issue.

  6. azazellj commented on Jan 31, 2026

    @azazellj

    Hello @shanshin.
    This is weird, but you can use this project, just put plugins in such order:

        kotlin("multiplatform")
        id("com.android.kotlin.multiplatform.library")
        id ("org.jetbrains.kotlinx.kover")
    

    if order is the same as in your example, an error does not appear.

  7. ShadowRZ commented on Feb 4, 2026

    @ShadowRZ

    @azazellj Tried with what you said but no issues at all, can you really reproduce this problem with the instructions you provided?

  8. Eroad-Egor-Egorov commented on Mar 8, 2026

    @Eroad-Egor-Egorov

    Getting the same issue. I am currently migrating project to AGP 9.0 with creating a separate module for Android for full KMP project

    Kover 0.9.7
    AGP 9.0.0

  9. Eroad-Egor-Egorov commented on Mar 8, 2026

    @Eroad-Egor-Egorov

    Actually resolved the issue by removing withHostTest {} from the configuration on shared module

  10. ShadowRZ commented on Mar 9, 2026

    @ShadowRZ

    @Eroad-Egor-Egorov Strange, earlier I tried with my own project without issues, I also can't reproduce this issue with the instructions in #772 (comment)

    Can you try to make a minimal reproduction and upload it?

  11. dsrees commented on Mar 9, 2026

    @dsrees

    Here is a demo repo which reproduces this issue for me. The key detail is that it uses a SQLDelight database and expects a driver for the tests that require a DB connection. The androidHostTest provides an actual JVM in-memory driver for test cases.

    In ./build.gradle.kts is the line apply<KoverGradlePlugin>() which, when uncommented, allows the sync to succeed.

  12. Yegorisa commented on Mar 16, 2026

    @Yegorisa

    @ShadowRZ well guess what, the order of the following plugins

        alias(libs.plugins.androidMultiplatformLibrary)
        alias(libs.plugins.kotlin.multiplatform)
        id ("org.jetbrains.kotlinx.kover")
    

    matters. If you put the plugins in this exact order, the error disappears. Previously the first two plugins were in opposite places

  13. ShadowRZ commented on Mar 16, 2026

    @ShadowRZ

    @dsrees I can reproduce the issue during import using the reproduction you provided, while @Yegorisa was right in that plugin order is significant.

    Cc @shanshin I think it should count as a reproduction

  14. added
    S: in progress
    and removed
    S: waiting for clarification
    on Mar 23, 2026
  15. added theissue type on Mar 23, 2026
  16. added a commit that references this issue on Mar 24, 2026
    72acb31
  17. added
    S: ready for release
    and removed
    S: in progress
    on Mar 24, 2026
  18. added a commit that references this issue on Mar 25, 2026
    9c300e1
  19. shanshin commented on Mar 25, 2026

    @shanshin
    Collaborator

    Fixed in 0.9.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugS: ready for release

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions