Kotlin Integration & Gradle Build Automation

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Your Swift code generates Java bindings, but Android doesn’t know about them yet. In this segment, you’ll configure Gradle to build Swift automatically, include generated Java sources, and make everything work together seamlessly.

Understanding the Build Pipeline

Here’s the complete build flow you’re about to configure:

dvidse ceocy foahsJyezcEhk (cust) Djuayul .za qosxuziay Danunabed Zahu (ehjap nu meuzbol) QEnxvufjJgulpQsumam (rlopn uzm tupakigov) wcacl qaapn (yinwezon) Tikaaz pu sjiNawz Zkumqi lutromup Ceysoc + Lise Raflejog iqvo EHQ Peicm pa ihmtobz!
Cefhwivo muokp xasoxone kdiv Ltebyo ga ILC

Configuring taskmanager-lib Gradle Module

You already have a basic build.gradle.kts in taskmanager-lib/ from the previous segment. Now you’ll expand it to include Swift build automation and JNI library management.

Clean the Project

After making these significant build configuration changes, it’s important to clean the build cache to avoid Gradle build failures.

Registering the Module with Gradle

Now tell Gradle about your new module. Open settings.gradle.kts at the project root and add:

Adding Dependencies to the App

Open app/build.gradle.kts and add these dependencies at the beginning of the dependencies block:

Publishing SwiftKitCore to Local Maven

Before building the Android app, you need to publish SwiftKitCore - the Java runtime library that swift-java uses. This ensures the generated Java code can find all the runtime methods it needs.

Understanding the Complete Build Process

When you run ./gradlew build, here’s the complete sequence:

Using Generated Classes in Kotlin

Now the generated TaskValidator class is available in Kotlin! Let’s use it in the repository.

How Data Flows Between Kotlin and Swift

When you call TaskValidator.validateTitle("Hi"), here’s the complete journey:

What You’ve Accomplished

In this segment, you’ve:

See forum comments
Download course materials from Github
Previous: Swift-Java Integration Next: Testing & Validation