Skip to content

fix: publish Android AARs without desktop native libraries (#214) - #360

Merged
devcrocod merged 5 commits into
developfrom
fix/214-android-target
Oct 29, 2026
Merged

devcrocod merged 5 commits into
developfrom
fix/214-android-target

Conversation

@devcrocod

Copy link
Copy Markdown
Collaborator

Fixes #214.

Android builds resolved the JVM jar of multik-openblas, which carries the desktop libraries under lib/linuxX64/, lib/macosArm64/ and lib/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.

  • Code shared by the JVM and Android targets moves from jvmMain to jvmAndAndroidMain; jvmMain is now desktop-only.
  • The Android .so ships in the multik-openblas AAR under jni/arm64-v8a/ and is loaded by name (AndroidLoader). It is still picked up from multik-openblas/build/libs, so the release steps don't change. The JVM jar no longer contains lib/arm64-v8a/.
  • The Android .so now links libc++ statically and is 16 KB aligned. The old one needed libc++_shared.so, which nothing shipped. build-native.yml checks both with llvm-readelf.
  • minSdk 28, compileSdk 37. The AAR metadata sets minCompileSdk = 28. Without that, the plugin would require apps to compile against 37.
  • Building now requires the Android SDK (ANDROID_HOME).

Behavior changes

  • Android: every module is published as an AAR (minSdk 28). Android projects should depend on the root coordinates (multik-default, multik-openblas, ...), not on multik-openblas-jvm. Native code is arm64-v8a only.
  • JvmNativeEngine.getMath(), getLinAlg() and getStatistics() throw EngineMultikException when the native library can't be loaded. Before, they failed later with UnsatisfiedLinkError.
  • DefaultEngine uses KEEngine when 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 dumps move to 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 same commonMain and jvmAndAndroidMain code.

Testing

  • apiCheck korroCheck jvmTest pass: core 678, kotlin 38 and openblas 78 tests.
  • I built the Android .so locally with NDK r27c. The new build-native.yml check fails on the 0.3.1 library (libc++_shared.so dependency, 4 KB alignment) and passes on the new one.
  • A throwaway Android app with compileSdk 36 depends on root multik-default from a local publication. Its APK contains only lib/arm64-v8a/libmultik_jni-androidArm64.so. Its instrumentation tests for the native and default engines pass, and the library loads:
    • on an Android 17 emulator with 16 KB pages, without page-size compat mode;
    • on a Pixel 9 Pro with Android 17 and 4 KB pages.
  • A desktop JVM app on macOS arm64 extracts the library from the jar and loads it.
  • There are no automated Android tests in the repo; the Android checks above were manual.
  • Not covered: jar extraction on Linux and Windows, because :multik-openblas:jvmTest loads through manualLoad. build-native.yml, including the new check, runs on this PR.

Checklist

  • Existing tests pass
  • New/updated tests for changed behavior
  • New/updated documentation if necessary

Copilot AI balanced review requested due to automatic review settings October 13, 2026 20:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Android packaging and failure behavior lack automated verification, fatal errors are swallowed, and several documentation surfaces remain inconsistent.

5 open findings
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.

Comment thread multik-openblas/build.gradle.kts Resolved
Comment thread CLAUDE.md Resolved
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
devcrocod force-pushed the fix/214-android-target branch from 1125123 to e162441 Compare October 29, 2026 14:01
@devcrocod
devcrocod merged commit c470f12 into develop Oct 29, 2026
6 checks passed
@devcrocod
devcrocod deleted the fix/214-android-target branch October 29, 2026 15:05
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.

build error: libmultik_jni-linuxX64.so is not an ABI even though I'm not building for that target

2 participants