· 2 min read Posted by Kevin Galligan
Part 2: Android Setup
GitPortal for KMP - Bidirectional
In Part 1 we created the tutorial repos, and connected CI to be able to communicate between them. In this post, we’ll configure the Android app to use the KMP code.
Configure the KMP code for Android
Open the Android app in Intellij IDEA or Android Studio. Once loaded, you’ll need to add the KMP modules to your project.
settings.gradle.kts
Open settings.gradle.kts
and include the modules breeds
and analytics
. The code to do so is in settings.gradle.kts
already, just commented out.
Remove:
include(":app")
Add/uncomment:
dependencyResolutionManagement {
versionCatalogs {
create("kmpLibs") {
from(files("library/gradle/libs.versions.toml"))
}
}
}
include(":app", ":breeds", ":analytics")
project(":breeds").projectDir = File("library/breeds")
project(":analytics").projectDir = File("library/analytics")
We’ve done a couple of things here.
First, we’ve added the Gradle version catalog from the library project. This allows us to configure the KMP modules with centralized versions and dependency coordinates.
Second, we added two KMP modules: analytics
and breeds
. They’re like any other Gradle module that you’d add to a Gradle project, with the projectDir
for each pointing to folders inside library
.
app/build.gradle.kts
Now open app/build.gradle.kts
. Add breeds
and analytics
as project dependencies. You’ll find them at the bottom of the file:
dependencies {
// Add these
implementation(project(":analytics"))
implementation(project(":breeds"))
implementation(libs.bundles.app.ui)
implementation(libs.koin.android)
coreLibraryDesugaring(libs.android.desugaring)
}
You can now sync the Gradle project, and your Android code should be able to access your KMP code! Select a device or simulator and run the project.