jw
10/02/2025, 6:40 PMcom.android.kotlin.multiplatform.library plugin creates a KotlinTarget (com.android.build.api.variant.impl.KotlinMultiplatformAndroidLibraryTargetImpl) whose platformType is "jvm" as opposed to "androidJvm". @Sebastian Sellmair [JB] indicated on another Slack workspace that this was intentional. A few questions have come up related to this.
How should we write code that operates on all targets (or a subset of them) and correctly differentiate JVM vs. Android. For example, Android differs from the JVM in having multiple variants by default, having two test compilations (times the number of product flavors), etc.
Should we prefer doing type checks on the target instead of using platformType? And the fact that this comes with extra burden when you have a compileOnly dependency on AGP, since you can no longer do a simple as? KotlinMultiplatformAndroidLibraryTarget without a try/catch on NoClassDefFoundException, or otherwise doing a Class.forName and then reflective isInstance.jw
10/02/2025, 6:40 PMralf
10/02/2025, 6:42 PMFor example, Android differs from the JVM in having multiple variants by defaultThe new plugin doesn't support that. But there are still two compilations for unit tests and device tests.
Sebastian Sellmair [JB]
10/02/2025, 6:43 PMjw
10/02/2025, 6:43 PMThe new plugin doesn't support that.Oh, yes. Thanks! I saw build types and flavors mentioned on the page for the new plugin, but it's in reference to migrating from the legacy one.
Wojtek Kalicinski
10/03/2025, 4:04 PMtapchicoma
10/06/2025, 4:19 PMplatformType to jvm was intentional, but I would advice against relying on target type to detect if it is Android.tapchicoma
10/13/2025, 6:31 AMplugins.withId(<id>) { } block, where plugin id is external target plugin ID. For example for KMP/Android it is com.android.kotlin.multiplatform.library.
• Check target and compilation types. For example for KMP/Android - target is KotlinMultiplatformAndroidLibraryTarget (docs) and compilation is KotlinMultiplatformAndroidCompilation (doc, there are more compilation types)
• For platformType publication issue we've created the following issue: KT-81505 New Android Multiplatform plugin publishes Android variants with kotlinPlatformType:jvm
In general you may expect in the future more external target types, so it is better to avoid on relying any external target is Android one.
And the fact that this comes with extra burden when you have aCould you file an issue for this with more detailed description of the problem? We need to think how to provide some help for this case.dependency on AGP, since you can no longer do a simplecompileOnlywithout a try/catch onas? KotlinMultiplatformAndroidLibraryTarget, or otherwise doing aNoClassDefFoundExceptionand then reflectiveClass.forName.isInstance
mbonnin
10/13/2025, 8:07 AMyou may expect in the future more external target types, so it is better to avoid on relying any external target is Android one.Not sure I get that one. You mean new values in the
KotlinPlatformType enum? It's OK if the changes are additives? Plugin authors will need a newer version of their plugins to support the new KotlinPlatformType but this is fine?Anton Lakotka [JB]
10/13/2025, 8:21 AMfun KotlinTarget.isNewAndroidKMP() = this is ExternalTarget && this.platformType == jvm
may fail in some other cases if someone else decided to tweak KMP via ExternalTarget API.
That is why this check should be rewritten into something like this:
fun KotlinTarget.isNewAndroidKMP() = this === androidExtension.kmpTarget()
i.e. check against some API that AGP would provide, as they are owners of their target.mbonnin
10/13/2025, 8:31 AMfun KotlinTarget.isNewAndroidKMP() = this is KotlinMultiplatformAndroidLibraryTarget
?Anton Lakotka [JB]
10/13/2025, 8:32 AMmbonnin
10/13/2025, 8:33 AMNoClassDefFoundException that Jake mention, only call isNewAndroidKMP() from plugins.withId("com.android.kotlin.multiplatform.library") { }