I'm working on migrating an Android library to KMP...
# multiplatform
j
I'm working on migrating an Android library to KMP and reading through the following guide on the Android developer site has me confused. In the guide the following quote indicates
androidLibrary{}
is no longer recommended. The guide contains the following excerpts:
Note: Since Kotlin Gradle Plugin version 2.2.0-Beta2 and Android Gradle Plugin version 8.12.0-alpha04, a new configuring block exists called
android{}
alongside the
androidLibrary{}
one. The
androidLibrary{}
block is deprecated and will be removed in a future release of AGP, so migrate to the
android{}
block.
This seems contradictory because adding a new KMP module in my project, it creates build.gradle.kts file that contains an
androidLibrary {}
. I'm using Android Studio Narwhal 3 Feature Drop and I have the most update to date version of the Kotlin Multiplatform plugin (0.9-251.26094-AS-85). Furthermore, there is additional code snippets in the guide that use
androidLibrary {}
. Can anyone lend some expertise on the subject and help clear up my confusion?
👀 1
t
The situation could be confusing here: • The oldest
android {}
DSL was once available in KMP plugin, but was recently removed. It was used to integrate with "com.android.application" or "com.android.library" plugins • Temporary
androidTarget {}
DSL was introduced to free
android
name, but still support the same Android plugins • Meanwhile
androidLibrary {}
name was used by new "com.android.kotlin.multiplatform.library" plugin • In the recent AGP 8.12 release "com.android.kotlin.multiplatform.library" plugin reclaimed
android {}
DSL
androidTarget {}
will be deprecated in Kotlin 2.3.0 release and removed in some following releases.
j
Should I migrate over to the
android {}
DSL or is it safe to continue to use
androidTarget {}
?
t
The best approach is to use "com.android.kotlin.multiplatform.library:8.12" +
android {}
namespace. As I wrote above
androidTarget {}
will be soon deprecated.
j
Sorry, I had a typo and I meant to put
androidLibrary {}
.
t
androidLibrary {}
AFAIK also will be deprecated in some future AGP releases
j
Either way, I will migrate over to
android {}
. Do you know when the plugin will be updated to use the correct DSL?
t
and only
android {}
will stay
<!subteam^S093FP0H16X> is it KMT plugin who maintains this functionallity?
j
Do you happen to know if switching from
androidLibrary {}
to the newly supported
android {}
is as simple as changing the name or are there additional changes that need to be made?
e
Its as simple as that.
🙏🏿 1
👌 1
p
That's some helpful history. We were using the androidLibrary version for a while but lots of the ide features (especially around dependencies) stopped working in androidMain so we went back to androidTarget. I'll have to take a look into the newer one
1