Giter Club home page Giter Club logo

rust_jni_android_example_wrapper's Introduction

Build a bridge and bring both sides together

A Rust JNI Android Example wrapper

Example of a simple bridge between Android Java JNI and a Rust library.

This library focuses on simple use cases (eg get a JArray from a JString,...). JStringArray are not yet part of the wrapper. I am still working on that, but as the length of a JArray doesn't have to be known at compile time with our wrapper that will work in most circumstances.

Rust functions are tested. Testing the wrapper functions in Rust is a bit more of a hassle. I might get into that another time.

Install & run

Dependencies

    rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android
    gedit ~/.cargo/config

Adjust and add the following part (Identify your NDK folder with the prebuilt files in your Android SDK location (similar to the paths shown))

[target.aarch64-linux-android]
ar = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar"
linker = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"

[target.armv7-linux-androideabi]
ar = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
linker = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"

[target.i686-linux-android]
ar = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-ar"
linker = "/home/username/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android28-clang"

save and exit file.

Download files & build rust part

git clone https://github.com/mad-de/rust_JNI_Android_example_wrapper
cd rust_JNI_Android_example_wrapper
./buildScript.command

Run / compile

  • Load android folder as a new project in Android SDK and run / build apk

Expected result

Screenshot from 2020-02-01 16-39-21

Run rust tests

cd rust
cargo test

Screenshot from 2020-02-01 16-43-43

rust_jni_android_example_wrapper's People

Contributors

mad-de avatar sleeptimegrt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.