· 2 min read Posted by Kevin Galligan

GitPortal for KMP Tutorial

Part 2: Android Setup

We have our repos set up. Let's add the KMP code to the Android app

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.

Status from the Part 1

You should have the template repos cloned to your local machine. We’ll be using the Android app repo in this post.

Configure the KMP code for Android

Open the Android app in Intellij 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, starting on line 53:

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 refresh the Gradle project, and your Android code should be able to access your KMP code!

Next - Part 3: iOS Setup