-
Notifications
You must be signed in to change notification settings - Fork 6
Building
Smjni comes with a portable CMake script that should work everywhere. It has been tested with
Apple Clang version 12.0.0 (clang-1200.0.32.2) from Xcode 12 Android Clang version (6454773 based on r365631c2) clang version 9.0.8 from NDK 21.3.6528147 MSVC 19.27.29112 from Visual Studio 16.7.6 GCC 9.3.0
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 other platfrom C++17 mode is required.
Clone this repository somewhere
Add the following to your CMakeLists.txt
add_subdirectory("/path/to/smjni" ${CMAKE_CURRENT_BINARY_DIR}/smjni)
#set relevant C++17 flag for your compiler here
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
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++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 ..
make
cd java
java -jar smjnitests.jar
On Linux you might need to modify the last command as follows
java -Djava.library.path=. -jar smjnitests.jar
- 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