David Nedrow
07/26/2024, 4:27 PMAngelos
07/27/2024, 9:24 AMDavid Nedrow
07/29/2024, 2:40 PMMatthew Feinberg
08/12/2024, 2:41 AMcomposeApp
folder and rename the copy to something based on the library name.
2. Make a top-level sample
folder and move the original composeApp
and any other target folders (iosApp
etc) inside it.
3. Fix up the various Gradle files to match the reorganized structure.
4. Change rootProject.name
if necessary to avoid conflicts
5. Replace references to libs.plugins.androidApplication
with references to libs.plugins.androidLibrary
6. Delete anything app-specific from the Gradle files like applicationId
, targetSdk
, versionCode
and versionName
in android {}
(you'll get a build error if you don't anyway)
7. Add your library as a dependency to the sample
module.
8. If you want to publish the library somewhere (I use GitHub's private gradle registry) add the maven-publish
plugin to Gradle and configure it appropriately.
It takes a bit of messing around the first time to get it to work right, but once you've done a few, it becomes second nature to adjust a wizard-generated project for use as a library.
The biggest pitfall I ran into was maven-publish
... unbeknownst to me, Kotlin Multiplatform gradle plugin automatically detects maven-publish
and does most of the configuration for you. So all you need to do is configure WHERE the library is being published and any meta data (version number, etc.). Don't try to configure what is published or you'll end up with duplicate things because Kotlin Multiplatform is already doing that work automatically (it stupidly took me days to figure this out, and the solution was just to delete most of the stuff I added in Gradle, and then it just worked...)
Keep in mind that there's a lot of new stuff coming down the pipeline with regard to library packaging formats for Kotlin in the future (there was a whole session on it in the last KotlinConf — if you're making libraries, it's very much worth a watch on YouTube!)