A library designed to simplify the usage of the Java Native Interface
C++
336
230 commits
updated Sep 25, 2026
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;
}
};
fbjni is Apache-2 licensed, as found in the LICENSE file.
219 followers · starred Oct 2023
C++
80.4%
Java
17.3%
CMake
1.2%
A library designed to simplify the usage of the Java Native Interface
C++
336
230 commits
updated Sep 25, 2026
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;
}
};
fbjni is Apache-2 licensed, as found in the LICENSE file.
219 followers · starred Oct 2023
C++
80.4%
Java
17.3%
CMake
1.2%