Skip to content

Add Android KMP library backend alongside legacy AGP integration - #280

Open
Milerius wants to merge 1 commit into
gobley:mainfrom
Milerius:fix-264-unsupported-android-kmp-plugin
Open

Add Android KMP library backend alongside legacy AGP integration#280
Milerius wants to merge 1 commit into
gobley:mainfrom
Milerius:fix-264-unsupported-android-kmp-plugin

Conversation

@Milerius

Copy link
Copy Markdown

Summary

  • split Android integration into backend delegates for legacy AGP (com.android.library/com.android.application) and the Android KMP library plugin (com.android.kotlin.multiplatform.library)
  • add Kotlin target compatibility mapping so Android KMP targets are treated as Android (androidJvm) in Cargo and UniFFI task planning
  • update Cargo and UniFFI wiring to avoid JVM/Android target misclassification and variant collisions on Android KMP projects
  • add a dedicated Gradle fixture project (tests:gradle:android-kmp-library) and include it in gradle test project set

Verification

  • ./gradlew :build-logic:gobley-gradle-cargo:test :build-logic:gobley-gradle-uniffi:test
  • ./gradlew :tests:gradle:android-kmp-library:assemble -Pgobley.projects.examples=false -Pgobley.projects.uniffiTests=false -Pgobley.projects.gradleTests=true
  • ./gradlew :tests:gradle:android-linking:assemble -Pgobley.projects.examples=false -Pgobley.projects.uniffiTests=false -Pgobley.projects.gradleTests=true

@Milerius
Milerius force-pushed the fix-264-unsupported-android-kmp-plugin branch from 1ade332 to 24020fe Compare February 22, 2026 15:09
@paxbun

paxbun commented Feb 24, 2026

Copy link
Copy Markdown
Member

Sorry for the late reply. I missed the notification 🙇 This looks good to me. My private issue is still tying me down right now, but I think I can merge this in the next (the final) version of 0.3.x. I'll let you know about any updates as soon as possible. Thanks for the contribution again!

Comment on lines +123 to +135
private fun Project.findAndroidSdkRoot(): File? {
val sdkFromProperties = rootProject.file("local.properties")
.takeIf(File::exists)
?.inputStream()
?.use { input ->
Properties().apply { load(input) }.getProperty("sdk.dir")
}
?.takeIf(String::isNotBlank)
?.let(::File)
?.takeIf(File::exists)
if (sdkFromProperties != null) {
return sdkFromProperties
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been working on a PR to add AGP v9 support and I think I found cleaner solution for getting these properties:
https://github.com/fegan104/gobley/pull/1/changes#diff-de3c62ac66007a176b7db6b1431bd2d59b83ad6b6d35a6f01dd73b615203ee70R43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are available in KotlinMultiplatformAndroidComponentsExtension so you don't need to rely on local.properties file parsing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. This should be retrieved via AGP extensions.

@paxbun paxbun added this to the 0.3.8 milestone Mar 31, 2026

@paxbun paxbun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Since this introduces more gradual changes than #282, after verifying binary API changes and doing some chores, I'll merge this first. Sorry for making you wait this long again.

Comment on lines +15 to +19
val KotlinTarget.gobleyPlatformType: KotlinPlatformType
get() = when {
this is KotlinMultiplatformAndroidTarget -> KotlinPlatformType.androidJvm
else -> platformType
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to KotlinTarget.platformType returning KotlinPlatformType.jvm instead of androidJvm, right? Seems like a good workaround, but I think there should be a better name. I want something like kmpAgpSafePlatformType, but this is more verbose than gobleyPlatformType.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safePlatformName would do? Along with a KDoc with the reason it's needed..

markus2610 added a commit to VisionLab-de/gobley that referenced this pull request May 15, 2026
gobley#280)

Add KotlinTargetPlatformUtils with gobleyPlatformType/isGobleyAndroidTarget
extensions that recognise KotlinMultiplatformAndroidLibraryTarget as androidJvm.
CargoPlugin, UniFfiPlugin, and GobleyKotlinMultiplatformExtensionDelegate now use
these helpers instead of direct KotlinAndroidTarget/platformType checks, so gobley
works with both the classic com.android.library KMP target and the new
com.android.kotlin.multiplatform.library target introduced in AGP 8+.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants