103f1d323a
Summary: Instead of including JNI source code in our repo and statically linking in parts of JNI, use the prebuilt shared library available from Maven. While working on fixing the `Intl.NumberFormat` crash in the GC, I got multiple weird exceptions with stack traces that didn't line up with `hermesLog` statements I had added to the code. I eventually suspected something was wrong with having multiple copies of JNI, and switching to the shared library from maven resolved the crashes. Reviewed By: tmikov Differential Revision: D28791954 fbshipit-source-id: 992bc04428795cc3154a229211c1a6f24add32d6 |
||
---|---|---|
.. | ||
.github | ||
cxx | ||
docs | ||
gradle | ||
java/com/facebook/jni | ||
manifest | ||
scripts | ||
test | ||
.gitignore | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
build.gradle | ||
googletest-CMakeLists.txt.in | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
host.gradle | ||
settings.gradle |
README.md
fbjni
The Facebook JNI helpers library is designed to simplify usage of the Java Native Interface. The helpers were implemented to ease the integration of cross-platform mobile code on Android, but there are no Android specifics in the design. It can be used with any Java VM that supports JNI.
struct JMyClass : JavaClass<JMyClass> {
static constexpr auto kJavaDescriptor = "Lcom/example/MyClass;";
// Automatic inference of Java method descriptors.
static std::string concatenate(
alias_ref<JClass> clazz,
// Automatic conversion to std::string.
std::string prefix) {
// Call methods easily.
static const auto getSuffix = clazz->getStaticMethod<JString()>("getSuffix");
// Manage JNI references automatically.
local_ref<JString> jstr = getSuffix(clazz);
// Automatic exception translation between Java and C++ (both ways).
// No need to check exception state after each call.
result += jstr->toStdString();
// Automatic conversion from std::string.
return result;
}
};
Documentation
- Why use a JNI wrapper?
- Set up your Android build with fbjni
- Quick reference to most features (great for copy/pasting!)
- Internal documentation for maintainers
License
fbjni is Apache-2 licensed, as found in the LICENSE file.