Failed to apply plugin during sync when using KMP Android library plugin

I'm not 100% sure, but I think that producer's reflection logic fails when a project uses the modern Android library plugin.

Versions:

  • library: 0.6.0
  • org.jetbrains.kotlin.multiplatform: 2.2.21
  • com.android.kotlin.multiplatform.library: 8.13.1

Steps to reproduce:

  1. Add the producer plugin to some KMP project.
  2. Add the Android library plugin.
  3. Try to sync.

Actual behavior: Error during sync

An exception occurred applying plugin request [id: 'dev.opensavvy.resources.producer', version: '0.6.0']
> Failed to apply plugin 'dev.opensavvy.resources.producer'.
   > Can not get final org.gradle.api.component.AdhocComponentWithVariants field org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetSoftwareComponentImpl.adhocComponent on org.jetbrains.kotlin.gradle.plugin.mpp.external.ExternalKotlinTargetSoftwareComponent

The stack trace is quite big, here's what looks like a relevant part:

Caused by: java.lang.IllegalArgumentException: Can not get final org.gradle.api.component.AdhocComponentWithVariants field org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetSoftwareComponentImpl.adhocComponent on org.jetbrains.kotlin.gradle.plugin.mpp.external.ExternalKotlinTargetSoftwareComponent
	at java.base/jdk.internal.reflect.MethodHandleFieldAccessorImpl.newGetIllegalArgumentException(Unknown Source)
	at java.base/jdk.internal.reflect.MethodHandleObjectFieldAccessorImpl.get(Unknown Source)
	at opensavvy.gradle.resources.producer.KotlinKt$initializeForKotlin$1.execute(Kotlin.kt:90)
	at opensavvy.gradle.resources.producer.KotlinKt$initializeForKotlin$1.execute(Kotlin.kt:26)
	at org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:124)

Expected behavior: Sync without errors.

Edited by Terenfear