Daniele Segato
10/23/2024, 7:19 AMdebugImplementation
dependency from the top level of an Android project, you’ll need to add an implementation dependency to the source set named androidDebug
. To minimize the effort you have to put in to deal with migration problems like this, you can add a dependencies {}
block inside the androidTarget {}
block:
however when I try to use androidTarget {}
in either the build.gradle.kts sourceSets block or inside a build-convention plugin I get this error:
The target 'android' already exists, but it was not created with the 'android' preset. To configure it, access it by name in `kotlin.targets`.
I’ve already tried applying the com.android.kotlin.multiplatform.library
before the org.jetbrains.kotlin.multiplatform
plugin without any change in the error message
And if I try using
getByName("androidDebug") { }
I get
KotlinSourceSet with name 'androidDebug' not found.
Daniele Segato
10/24/2024, 6:47 AMcom.android.kotlin.multiplatform.library
plugin over com.android.library
.
they are both plugins released by Google with AGP, the first is newer and is supposedly going to eventually replace com.android.library
for multiplatform libraries using Android (but I actually hope they’ll take another route, cause multiplatform and android library shouldn’t be put together IMHO).
The 2 plugin conflict with each other, if you use com.android.library
you cannot also use com.android.kotlin.multiplatform.library
.
If you use the regular com.android.library
than it does what is needed to init the android component and therefore you can than use androidTarget { }
inside the kotlin { }
section of configuration for the org.jetbrains.kotlin.multiplatform
plugin.
AND if you use com.android.library
android studio will support compose previews in androidMain
while if you use com.android.kotlin.multiplatform.library
the preview will not be available.
Conclusion of all this: do not use com.android.kotlin.multiplatform.library
, at least not yet.Daniele Segato
10/24/2024, 6:51 AMdebutImplementation
with dependencies using com.android.kotlin.multiplatform.library
(which might not mean there isn’t one, I just couldn’t find one)Gabriel Santana
03/17/2025, 5:13 PM