I am writing a wrapper class for C++ ".so". I want to use the library in Java application and Android app using JNI. So I have to create header file and cpp file which will do JNI calls. I could use that on Linux in Java application.
The steps I followed:
Created java class and called native functions in that class
public class TestWrapper { static { System.load("/home/native.so"); } public static void main(String[] args) { new TestWrapper().TestWrapper(); } private native void sayHello(); }Created header file and cpp file. CCP contains following code
JNIEXPORT void JNICALL Java_TestWrapper_sayHello(JNIEnv *, jobject){ uint16_t data = 0; void (*func_print_name)(const uint16_t*); void* handle = dlopen("libCppTobeUsed.so.0", RTLD_LAZY); if (handle){ *(void**)(&func_print_name) = dlsym(handle, function_name); func_print_name(&data); dlclose(handle); std::cout << "data received .." << data << std::endl; } } }Compiled this cpp class and generated "native.so"
This is working fine. The "native.so" could call the fuction form "ibCppTobeUsed.so.0" when called from TestWrapper.java.
I want to use same library for android as well. So, I have to write wrapper class all over again in Android NDK? Or I can compile my "native.so" for Android platform?
If I try to use it directly, I get error
"install_failed_no_matching_abis".
.sowritten in? If it was compiled for Linux it could be x86 or x64 which won't run on ARM devices..sowith the NDK. The JNI wrapper classes need to be done for all architectures regardless.