Repository navigation
fix: publish Android AARs without desktop native libraries (#214) - #360
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Android packaging and failure behavior lack automated verification, fatal errors are swallowed, and several documentation surfaces remain inconsistent.
5 open findings
Avoid swallowing fatal VM errors during native fallback · New Add CI verification for JNI libraries in the assembled AAR · New Update I/O documentation to include Android support · New Include Android in all page platform summaries · New Update page summaries to include Android OpenBLAS support · New
What changed in this PR
Adds proper Android AAR variants across Multik, separating Android and desktop native libraries while enabling runtime fallback to the Kotlin engine.
Changes:
- Adds Android targets and shared JVM/Android source sets.
- Packages the ARM64 JNI library in the OpenBLAS AAR.
- Updates engine loading, publication metadata, CI, and Android documentation.
| File | Description |
|---|---|
settings.gradle.kts |
Adds Google repository. |
README.md |
Documents Android support. |
multik-openblas/src/jvmMain/.../Loader.kt |
Makes desktop loading idempotent and lazy. |
multik-openblas/src/jvmAndAndroidMain/resources/...Engine |
Registers the native engine. |
multik-openblas/src/jvmAndAndroidMain/.../JniStat.kt |
Shares statistics JNI bindings. |
multik-openblas/src/jvmAndAndroidMain/.../JniMath.kt |
Shares math JNI bindings. |
multik-openblas/src/jvmAndAndroidMain/.../JniLinAlg.kt |
Shares linear-algebra JNI bindings. |
multik-openblas/src/jvmAndAndroidMain/.../JvmNativeEngine.kt |
Adds explicit loading failures. |
multik-openblas/src/androidMain/.../Loader.android.kt |
Adds Android library loading. |
multik-openblas/multik_jni/CMakeLists.txt |
Statically links libc++ and aligns ELF segments. |
multik-openblas/build.gradle.kts |
Separates desktop JAR and Android AAR libraries. |
multik-openblas/api/jvm/multik-openblas.api |
Relocates JVM API dump. |
multik-kotlin/src/jvmAndAndroidMain/resources/...Engine |
Registers the Kotlin engine. |
multik-kotlin/api/jvm/multik-kotlin.api |
Relocates JVM API dump. |
multik-default/src/jvmMain/.../DefaultEngineFactory.kt |
Removes desktop-only factory. |
multik-default/src/jvmAndAndroidMain/resources/...Engine |
Registers the default engine. |
multik-default/src/jvmAndAndroidMain/.../DefaultStatistics.kt |
Shares default statistics dispatch. |
multik-default/src/jvmAndAndroidMain/.../DefaultMathEx.kt |
Shares extended math dispatch. |
multik-default/src/jvmAndAndroidMain/.../DefaultMath.kt |
Shares default math dispatch. |
multik-default/src/jvmAndAndroidMain/.../DefaultLinAlgEx.kt |
Shares extended linear algebra. |
multik-default/src/jvmAndAndroidMain/.../DefaultLinAlg.kt |
Shares default linear algebra. |
multik-default/src/jvmAndAndroidMain/.../DefaultJvmEngine.kt |
Adds shared package source. |
multik-default/src/jvmAndAndroidMain/.../DefaultEngineFactory.kt |
Adds native-load fallback. |
multik-default/build.gradle.kts |
Configures shared Android dependencies. |
multik-default/api/jvm/multik-default.api |
Relocates JVM API dump. |
multik-core/src/jvmAndAndroidMain/.../JVMIteratingNDArray.kt |
Shares sorted-set conversions. |
multik-core/src/jvmAndAndroidMain/.../DataType.jvm.kt |
Shares JVM data-type resolution. |
multik-core/src/jvmAndAndroidMain/.../ComplexDouble.jvm.kt |
Shares complex-number implementation. |
multik-core/src/jvmAndAndroidMain/.../npy.kt |
Exposes NPY/NPZ I/O on Android. |
multik-core/src/jvmAndAndroidMain/.../io.kt |
Shares generic file I/O. |
multik-core/src/jvmAndAndroidMain/.../csv.kt |
Exposes CSV I/O on Android. |
multik-core/src/jvmAndAndroidMain/.../Engine.kt |
Shares service-based engine discovery. |
multik-core/build.gradle.kts |
Moves JVM dependencies to shared source set. |
gradle/libs.versions.toml |
Adds AGP dependency. |
docs/topics/gettingStarted/multik-on-mobile.md |
Documents Android engines and fallback. |
docs/topics/gettingStarted/multik-on-JVM.md |
Separates Android guidance. |
docs/topics/gettingStarted/multik-on-different-platforms.md |
Adds Android platform details. |
docs/topics/FAQ.md |
Updates Android support guidance. |
CLAUDE.md |
Updates repository development guidance. |
buildSrc/src/main/.../SyncIntoSubdirectory.kt |
Adds generated-resource synchronization task. |
buildSrc/src/main/kotlin/multik.base.gradle.kts |
Adds the common Android target. |
buildSrc/build.gradle.kts |
Adds AGP to build logic. |
.github/workflows/build.yml |
Compiles Android targets in CI. |
.github/workflows/build-native.yml |
Validates Android native linkage and alignment. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Android builds resolved the JVM jar of multik-openblas, which carries the desktop libraries under lib/linuxX64, lib/macosArm64 and lib/mingwX64, and AGP rejects those as non-ABI directories. Every module now has an Android target (com.android.kotlin.multiplatform.library, minSdk 28) and is published as an AAR, so Android builds never see the desktop jar. - Code shared by the JVM and Android targets moves to jvmAndAndroidMain; jvmMain is desktop-only. - The Android .so ships in the multik-openblas AAR under jni/arm64-v8a and is loaded by name; the JVM jar no longer contains it. - The Android .so links libc++ statically and is 16 KB aligned; build-native.yml checks both with llvm-readelf. - DefaultEngine falls back to KEEngine when the native library cannot be loaded; JvmNativeEngine throws EngineMultikException in that case. - API dumps move to api/jvm (BCV per-target layout), content unchanged.
The IDE writes it with sdk.dir now that every module applies the Android Gradle plugin.
…tik-core AAR commons-csv marks CSVPrinter.endOfRecord() with @SuppressFBWarnings but declares spotbugs-annotations optional, so R8 failed every minified app that depends on multik with "Missing class edu.umd.cs.findbugs.annotations.SuppressFBWarnings". The rule is published as a consumer keep rule, so it reaches apps through any multik module.
…las AAR The complex double dot builds its result in native code by calling the ComplexDouble(re, im) factory through FindClass/GetStaticMethodID. R8 can't see that call, so in minified apps it inlined the factory and dropped ComplexDouble_jvmKt, and the lookup aborted the process (SIGABRT). The AAR now ships consumer keep rules for that factory and for the native methods of the JNI classes.
CSV/NPY/NPZ file I/O is in jvmAndAndroidMain, but the I/O pages and the FAQ still called it JVM-only, and several summaries listed platforms without Android or said mobile runs only on the Kotlin engine. Also fix two NPZ examples: writeNPZ takes a Path, not a String, and Path.of needs API 34 on Android, so both now use kotlin.io.path.Path.
devcrocod
force-pushed
the
fix/214-android-target
branch
from
October 29, 2026 14:01
1125123 to
e162441
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #214.
Android builds resolved the JVM jar of
multik-openblas, which carries the desktop libraries underlib/linuxX64/,lib/macosArm64/andlib/mingwX64/. AGP rejects those as non-ABI directories. Every module now has an Android target (com.android.kotlin.multiplatform.library, AGP 9.4.1) and publishes an AAR. Gradle's variant-aware resolution gives Android consumers the AARs, so they never see the desktop jar. The AARs contain only Android native code, and the JVM jar only desktop code.jvmMaintojvmAndAndroidMain;jvmMainis now desktop-only..soships in themultik-openblasAAR underjni/arm64-v8a/and is loaded by name (AndroidLoader). It is still picked up frommultik-openblas/build/libs, so the release steps don't change. The JVM jar no longer containslib/arm64-v8a/..sonow links libc++ statically and is 16 KB aligned. The old one neededlibc++_shared.so, which nothing shipped.build-native.ymlchecks both withllvm-readelf.minCompileSdk = 28. Without that, the plugin would require apps to compile against 37.ANDROID_HOME).Behavior changes
multik-default,multik-openblas, ...), not onmultik-openblas-jvm. Native code isarm64-v8aonly.JvmNativeEngine.getMath(),getLinAlg()andgetStatistics()throwEngineMultikExceptionwhen the native library can't be loaded. Before, they failed later withUnsatisfiedLinkError.DefaultEngineusesKEEnginewhen the native library can't be loaded, for example on Intel Macs or in Android unit tests on the host JVM. Before, it failed.api/jvm/, because BCV switches to its per-target layout once a module has two JVM targets. Their content is unchanged. BCV 0.18 doesn't dump the Android target; its API is the samecommonMainandjvmAndAndroidMaincode.Testing
apiCheck korroCheck jvmTestpass: core 678, kotlin 38 and openblas 78 tests..solocally with NDK r27c. The newbuild-native.ymlcheck fails on the 0.3.1 library (libc++_shared.sodependency, 4 KB alignment) and passes on the new one.multik-defaultfrom a local publication. Its APK contains onlylib/arm64-v8a/libmultik_jni-androidArm64.so. Its instrumentation tests for the native and default engines pass, and the library loads::multik-openblas:jvmTestloads throughmanualLoad.build-native.yml, including the new check, runs on this PR.Checklist