-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Fork from https://gist.github.com/gnuanu/252fd406f48f7da2c1c7
Hello World with - JNI - Android Library
- GNU/Linux
- IntelliJ IDEA
- My working directory is $JNI
- C++ IDE (QtCreator).
- NDK should be installed and ndk-build should be available in $PATH
- javah should be available in $PATH
- Create and Empty Project Named JNI (at location $JNI)
- Create a new Android application module named JNIHelloWorld.
- Package Name - com.jnisample.JNIHelloWorld
- Create one activity JNIActivity and define one native function getNativeMessage()
- Build the project
- Create a folder jni inside $JNI/JNIHelloWorld
- In Terminal(command line) move to $JNI/out/production/JNIHelloWorld directory (This is where the java files get compiled to class files by IDEA; Verify the directory structure is same as the package name com/jnisample/JNIHelloWorld/JNIActivity.class)
- Create the header for the native function using javah
$ javah $JNI/JNIHelloWorld/jni com.jnisample.JNIHelloWorld.JNIActivity
Java 8+ :
$ javac com.jnisample.JNIHelloWorld.JNIActivity.java -h $JNI/JNIHelloWorld/jni
With classpath Android.jar:
$ javah -classpath /home/<USER>/Android/Sdk/platforms/android-XX/android.jar:app/build/classes/ -d $JNI/jni com.jnisample.JNIHelloWorld.JNIActivit
- Create a C++ class with name HelloWorld inside of$JNI/JNIHelloWorld/jni
- Create define a member function getNativeString() which returns a string
Implement the entry methodcom_jnisample_JNIHelloWorld_JNIActivity_getNativeMessagedefined in headercom_jnisample_JNIHelloWorld_JNIActivity.h
DefineAndroid.mkandApplication.mkinside of$JNI/JNIHelloWorld/jni
Android.mk example:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-world
LOCAL_SRC_FILES := HelloWorld.cpp
include $(BUILD_SHARED_LIBRARY)
Application.mk example:
APP_ABI := armeabi-v7a #TARGET ARCH
APP_PLATFORM := android-21
- In Terminal, move to directory$JNI/JNIHelloWorld
# Build the Shared Object using the commandndk-build
$ ndk-build
On successful build, the Shared Object file libmynative.so will be copied to $JNI/JNIHelloWorld/libs/armeabi-v7a
- Build the android project in IntelliJ IDEA
# Deploy and Run
The vendor interface is validated by the Vendor Test Suite (VTS), which is analogous to the Compatibility Test Suite (CTS). You can use VTS to automate HAL and OS kernel testing in both legacy and current Android architectures.
- Research
- VTS
- CTS