Java.cr
Java Native Interface (JNI) bindings (and generator) for Crystal
Install / Use
/learn @ysbaddaden/Java.crREADME
Java Native Interface (JNI) bindings (and generator) for Crystal
Generate Java bindings through the Java Native Interface (JNI) automatically
from Java classes using the javap tool distributed with the JDK.
The main goal is to generate bindings for the Android SDK. This project is thus
for the most usable widget and communication classes (e.g.
android.app.Activity, android.os.Handler or android.widget.TextView).
More complex classes, mostly those relying on generics and wildcards will
probably fail, or generate invalid Crystal code.
Install
Add the shard to your shard.yml dependencies:
dependencies:
java:
github: ysbaddaden/java.cr
Usage
Let's generate some bindings for an Android project. First we must add the
target platform android.jar to CLASSPATH. For example. Let's also add the
project local folder where the Android SDK will store the compiled classes.
export CLASSPATH=bin/classes:/opt/android-sdk/platforms/android-23/android.jar
Let's generate some bindings, this will load the definition of the specified
classes, potentially following classes found, then generate the Crystal bindings
into namespace separated folders. Pass --help for the full list of options.
lib/java/bin/generator --output src --no-follow \
android.app.Activity \
android.os.Bundle \
android.os.Message \
android.os.Handler
You may now just use it:
require "android/os/bundle"
require "android/os/message"
bundle = Android::Os::Bundle.new
bundle.put_char_sequence("action", "setText")
bundle.put_char_sequence("text", "hello world")
message = Android::Os::Message.new
message.set_data(bundle)
TODO
- [ ] fix bugs
- [ ] write tests
Authors
- Julien Portalier (creator, maintainer)
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
