java
Version, currently master branch1 version
- master branchlatestDec 25, 2016
github.com/ysbaddaden/java.cr
Java Native Interface (JNI) bindings (and generator) for Crystal
25 stars
1 dependent
License: Apache-2.0
Installation
# Add this to your shard.yml
dependencies:
java:
github: ysbaddaden/java.cr
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
- no constraint declared
- License
- Apache-2.0
- Author
- Julien Portalier <julien@portalier.com>
- Target
generatorfrom src/generator.cr
Dependencies
Development Dependencies
- minitest*github: ysbaddaden/minitest.crdev
README
# 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.
```sh
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.
```sh
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:
```crystal
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)
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Dec 25, 2016
- Indexed
- yes
Dependents
Repository
github.com/ysbaddaden/java.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 1