Skip to content

ClassCastException sync error when using plugin #406

@skolson

Description

@skolson

I have a github repo that I just converted to JUnit 6.0.2 and mannodermaus 2.0.0 and as of today 2.0.1. It is using AGP 9 and the new Android KMP library plugin. Android device tests run fine in this repo after conversion. But I can't enable the mannodermaus plugin in build.gradle.kts as this error occurs during sync:

Caused by: java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.KotlinMultiplatformAndroidLibraryExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.api.dsl.CommonExtension (com.android.build.gradle.internal.dsl.KotlinMultiplatformAndroidLibraryExtensionImpl$AgpDecorated_Decorated and com.android.build.api.dsl.CommonExtension are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @4dd58522)
	at com.android.build.api.extension.impl.AndroidComponentsExtensionImpl$finalizeDsl$1.execute(AndroidComponentsExtensionImpl.kt:54)
	at com.android.build.api.extension.impl.DslLifecycleComponentsOperationsRegistrar.executeDslFinalizationBlocks(DslLifecycleComponentsOperationsRegistrar.kt:44)
	at com.android.build.gradle.internal.plugins.KotlinMultiplatformAndroidPlugin.afterEvaluate(KotlinMultiplatformAndroidPlugin.kt:352)
	at com.android.build.gradle.internal.plugins.KotlinMultiplatformAndroidPlugin.access$afterEvaluate(KotlinMultiplatformAndroidPlugin.kt:130)
	at com.android.build.gradle.internal.plugins.KotlinMultiplatformAndroidPlugin$createTasks$1.execute(KotlinMultiplatformAndroidPlugin.kt:296)
	at com.android.build.gradle.internal.plugins.KotlinMultiplatformAndroidPlugin$createTasks$1.execute(KotlinMultiplatformAndroidPlugin.kt:291)
	at org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:124)
	at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction$1.run(DefaultListenerBuildOperationDecorator.java:173)

In build.gradle.kts, if I comment out the mannodermaus plugin, the sync error stops and android unit tests run fine. If I uncomment the plugin line, the sync fails so it is easy to recreate. The plugins block in question looks like this:

plugins {
    libs.plugins.also {
        alias(it.kotlin.multiplatform)
        alias(it.android.kmp.library)
        alias(it.kotlinx.atomicfu)
        alias(it.kotlin.cocoapods)
        alias(it.dokka.base)
        alias(it.maven.publish.vannik)
        // alias(it.android.jupiter) // this currently causes a sync error ClassCastException
    }
}

The repo for re-creating this is Multiplatform IO library . I will push up the current commit with the JUnit 6 changes later today. After that the repo can be used to recreate this error by uncommenting the above alias line and running a sync.

AGP version is 9.1.0-alpha04. I have tried this with Gradle 9.2.1 and 9.3.0-rc-3. Both behave the same. The repo in github is using 9.2.1. Also tried mannodermaus 2.0.0 and 2.0.1, both act the same. The repo is using 2.0.1. Instrumented unit tests run fine without the plugin applied, so I'm unsure if it is doing anything in this configuration.

I have another repo that this error didn't occur. but I'm unsure what else is different about it. So the above error may not always be happening.

Repo push complete, can now be used to recreate error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions