Skip to content

Android support #14

Open
Open

Description

@cecavac

Java and Kotlin bindings seem to work well on a standard JVM, but I haven't been able to get them working on Android without modifying the Clojure runtime.

Before going any further, I'd like to ask: Is Android support something YAMLStar would be interested in supporting?

I've explored two possible approaches and wanted to share my findings.

1. Making the Clojure runtime work on Android

The first issue I encountered was this kind of error:
clojure.lang.ExceptionInfo: Unknown YAML parser plugin: reference. Available: none {:parser "reference", :available ()}

But such problems can be addressed by extending AOT compilation https://github.com/yaml/yamlstar/blob/v0.1.25/java/project.clj#L30 and including additional namespaces such as yamlstar.plugin.parser.reference and some others.

However, a more fundamental issue is the following crash:

E  FATAL EXCEPTION: main
Process: com.celecavac.yamlstar2, PID: 20282
java.lang.ExceptionInInitializerError
at yaml_parser.parser$chars_rep$chars_rep_fn__1091.invoke(parser.cljc:1255)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
...
Caused by: java.lang.NoSuchMethodException: canAccess [class java.lang.Object]
at java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:991)
at clojure.lang.Reflector.<clinit>(Reflector.java:39)

I was able to get it running by replicating xlisp/clojure-android@620f584 and using a locally built Clojure JAR. It's not a very nice approach and without having something like this in Clojure upstream, it might be a no go.
I haven't tested it extensively, and there may be other compatibility issues.

2. Native Compilation

Another approach would be to compile this to native code for Android's 4 main ABIs and provide a small JNI layer.
The downside is that Android would need another set of Kotlin (and/or Java) bindings, e.g. yamlstar/kotlin-android. The generated AAR would be somewhat larger due to 4x native libraries, but on the upside, there would be no transitive dependencies.

I experimented with this a bit on ARM64 Android device, and it seemed to work fine.
If native Android support is of interest, I could share more info about the build setup. It produces the following AAR

$ ls -lh kotlin-yamlstar-android-0.1.24.aar
-rw-rw-r-- 1 cecavac cecavac 24M Oct 17 12:55 kotlin-yamlstar-android-0.1.24.aar

After unpacking it, the native library sizes are:

ABI libyamlstar.so libyamlstar-jni.so
arm64-v8a 17 MB 9.2 KB
armeabi-v7a 19 MB 7.6 KB
x86 19 MB 7 KB
x86_64 19 MB 8.2 KB

Activity

  1. ingydotnet commented on Oct 20, 2026

    @ingydotnet
    Member

    YAMLScript and YAMLStar are very similar and share a lot of their code.
    FYI, you can use YAMLScript exactly like YAMLStar. Without using !-ys tags it works the same, but YAMLStar has the new promising plugin system.
    YAMLStar started as a reduced codebase of YAMLScript.
    They both are written in Clojure.
    They used to be compiled to binaries yaml and libyamlstar.so using GraalVM native-image compiler.
    Now they use Glojure (same Clojure source code) to compile to Go code which compiles to those binaries and for many more platforms.

    There are 32 language bindings:

    • Most languages use FFI to bind to libyamlstar.so. This allows us to target almost every language.
    • Go binding is just Go code. That's nice because Go hates FFI.
    • Java, Kotlin and Scala I left as Java jars. This makes sense because FFI is painful in Java. One issue is that the Java code uses the SnakeYAML YAML parser and Glojure uses the go-yaml parser. These aren't 100% compatible yet (but mostly good enough and can both be improved).

    I'd like to see YSs get to as many places as possible. I don't know much about Android programming yet, but I do have YAMLScript programs running as Wasm on andriod and ios. See https://gloathub.org/ and https://yamlschema.org/
    YAMLStar and YAMLScript have wasm-p1 releases. One thing I can easily do is release them as browser wasm binaries.

    The internet told me that "Yes, Go code can be compiled to run natively on Android".

    I just checked and there's an android channel on the clojurians slack https://clojurians.slack.com/archives/C07JPKQ5S/p1779722437051339

    The last message is:

    🚀 Old project, revived: Clojure 1.13 now runs on Android!

     I ported Clojure 1.13 to run on Android (Dalvik / ART) — and not just loading
      it: it supports on-device dynamic eval (JVM bytecode → d8 → DEX, compiled at
      runtime). So you get a real REPL-style "evaluate Clojure live" experience right
      on the phone 😄

     Why it's neat
      • Tracks the latest Clojure (1.13) — not stuck on the old 1.7 branch
      • The changes are fully transparent and zero-overhead on the JVM — the Android
        path only kicks in when java.vm.name == "Dalvik"
      • Verified on an Android API 36 emulator: boot → AOT calls → on-device eval, all green

     Two repos
      • Patched Clojure 👉 https://github.com/xlisp/clojure-android
      • Runnable Android demo 👉 https://github.com/xlisp/clojure-android-demo

    To finally answer your question "Before going any further, I'd like to ask: Is Android support something YAMLStar would be interested in supporting?"...

    Yes, sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions