-
Notifications
You must be signed in to change notification settings - Fork 3
Building
Smjni originated on Android so it comes with Android.mk and build.gradle for ndk-build and experimental Gradle plugin respectively. In addition it provides portable CMake script that should work everywhere. Instructions for users of other build systems are provided at the end of this section
Smjni requires to be built with RTTI and exceptions enabled. It should work with GNU STL or LLVM libc++. It might or might not work with STLPort. As on every othr platfrom C++14 mode is required.
Clone this repository somewhere
In your Android.mk you should have the following settings in addition to other flags
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_CPPFLAGS := -std=gnu++14Specify dependency on smjni as follows
LOCAL_STATIC_LIBRARIES += smjniand at the end add
include /path/to/smjni/Android.mkClone this repository somewhere
In your settings.gradle specify
include ...all the other projects you have..., ':smjni'
project(':smjni').projectDir = new File('/path/to/smjni')In your JNI module build.gradle specify the following in addition to other JNI settings you already have
model {
android {
ndk {
cppFlags.add("-std=gnu++14")
cppFlags.add("-fvisibility=hidden")
cppFlags.add("-frtti")
cppFlags.add("-fexceptions")
}
sources {
main {
jni {
dependencies {
project ":smjni" linkage "static"
}
}
}
}
}Clone this repository somewhere
Add the following to your CMakeLists.txt
add_subdirectory("/path/to/smjni" ${CMAKE_CURRENT_BINARY_DIR}/smjni)
#set relevant C++14 flag for your compiler here
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
target_link_libraries(your_target_name smjni ${JAVA_JVM_LIBRARY})You will need to
- Build all *.cpp files under src directory and link them with your code
- Add inc directory to your include path
Build requires C++14 and a modern standard library.
This library is no longer actively maintained.
For an actively maintained and supported fork please migrate to SimpleJNI at https://github.com/gershnik/SimpleJNI
- Building
-
User's Guide
Declaring Java Types
Accessing Methods and Fields
Representing Java Classes
Implementing Native Methods
Smart References
Error Handling
Obtaining JNIEnv
Initialization
Strings
Arrays
Direct Buffers
Booleans
Sizes -
JniGen Code Generator
Integrating JniGen
Annotations
Processor Options