-
Notifications
You must be signed in to change notification settings - Fork 6
Building
SimpleJNI comes with a portable CMake script that should work everywhere. It has been tested with
- Apple Clang version 3.0.0.13000029 (clang-1300.0.29.3) from Xcode 13
- Android Clang version 12.0.5 (7284624, based on r416183b) from NDK 23.0.7599858
- MSVC 19.29.30133.0 from Visual Studio 16.11.2
- GCC 9.3.0
SimpleJNI 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 other platfrom C++17 mode is required.
First have CMake fetch SimpleJNI library (replace the GIT_TAG
value with the version you want to fetch.)
include(FetchContent)
FetchContent_Declare(SimpleJNI
GIT_REPOSITORY git@github.com:gershnik/SimpleJNI.git
GIT_TAG 3.5
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SimpleJNI)
Then declare dependency on SimpleJNI in your library or executable
#The library name is smjni for backward copatibility
target_link_libraries(your_target_name smjni)
Clone this repository somewhere
Add the following to your CMakeLists.txt
add_subdirectory("/path/to/SimpleJNI" ${CMAKE_CURRENT_BINARY_DIR}/SimpleJNI)
#set relevant C++17 flag for your compiler here
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
#The library name is smjni for backward copatibility
target_link_libraries(your_target_name smjni)
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++17 and a modern standard library.
The code generator uses Gradle build system. The easiest way to build it is to open jnigen
folder in Android Studio or IntelliJ and build from there.
Alternatively you can use command line
cd jnigen
./gradlew assemble
The jnigen.jar
and jnigen-annotations.jar
will be produced in jnigen/build
folder.
Tests build and execution is driven from C++ and uses CMake. CMake build invokes Gradle to build Java parts as necessary. You should have CMake in your PATH for this to work.
cd tests
mkdir build
cd build
cmake ..
#this runs native functionality tests
cmake --build . --config Debug --target run-jar
#this runs JniGen code generator tests
cmake --build . --config Debug --target run-java-tests
- 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