diff --git a/App_Resources/Android/app.gradle b/App_Resources/Android/app.gradle index 0e24319a..03846d58 100644 --- a/App_Resources/Android/app.gradle +++ b/App_Resources/Android/app.gradle @@ -255,6 +255,10 @@ def faceclawVersionCode = { return parts[0] * 10000 + parts[1] * 100 + parts[2] }() +// ios-port packages commonMain in an AAR. Keeping this conditional lets the +// source relocation merge there without compiling the shared classes twice. +def faceclawDependencies = new groovy.json.JsonSlurper().parse(file("$rootDir/../../package.json")).dependencies ?: [:] + android { compileSdkVersion 35 buildToolsVersion "35" @@ -262,6 +266,11 @@ android { sourceSets.main { jniLibs.srcDirs += ["$projectDir/src/main/jniLibs"] + // Keep portable Kotlin at the same path as ios-port's KMP commonMain. + // main compiles it directly with the existing Android Kotlin plugin. + if (!faceclawDependencies.containsKey("@faceclaw/kotlin")) { + java.srcDirs += ["$rootDir/../../native/kotlin/shared/src/commonMain/kotlin"] + } } defaultConfig { @@ -288,6 +297,15 @@ android { } } +// NativeScript can retain deleted App_Resources sources in its generated +// project. Remove the former copy before Kotlin compilation after this move. +def removeLegacyKotlinBridgeSource = tasks.register("removeLegacyKotlinBridgeSource", Delete) { + delete file("$projectDir/src/main/java/com/faceclaw/shared/KotlinBridge.kt") +} +tasks.matching { it.name.startsWith("compile") && it.name.endsWith("Kotlin") }.configureEach { + dependsOn removeLegacyKotlinBridgeSource +} + tasks.matching { it.name == "preBuild" }.configureEach { dependsOn tasks.named("prepareFaceclawNativeLibs") dependsOn tasks.named("prepareFaceclawLlama") diff --git a/App_Resources/Android/src/main/java/com/faceclaw/shared/KotlinBridge.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/shared/KotlinBridge.kt similarity index 89% rename from App_Resources/Android/src/main/java/com/faceclaw/shared/KotlinBridge.kt rename to native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/shared/KotlinBridge.kt index 809537dd..66f1ebfe 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/shared/KotlinBridge.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/shared/KotlinBridge.kt @@ -6,7 +6,7 @@ interface KotlinBridgeListener { } /** - * First step toward commonMain: only portable Kotlin, with no Android/JVM APIs. + * Portable Kotlin at the same commonMain source path used by ios-port. * Calls and callbacks are synchronous on the caller's thread. The listener is * used only during roundTrip and is never retained. */