Any thoughts or conversation about JVM / JRuby / Android for Crystal

If you are cross-compiling you get an object file that can be linked into a shared library, so the main difference is whether the program’s entry point is main or something else (ANativeActivity_onCreate by default). So writing an Android app in pure Crystal is definitely doable, as long as you ensure that the new entry point more or less mimics the runtime initialization in fun main, and that no other shared libraries use Crystal as it avoids the complication of linking multiple Crystal runtimes.

This is what it may look like (the unsafe class properties are defined here). Afterwards you can do anything you want at the top level, like using an app glue. See Hello World from Android ARM64 for details and also Add the ability to create a dynamic library · Issue #921 · crystal-lang/crystal · GitHub.

Naturally, most Java-specific functionality still has to be accessed through JNI bindings for Crystal. I haven’t looked into Ruboto yet but Ruby + Crystal for mobile development sounds quite attractive.

1 Like