java-native-interface

How to create HashMap<String, String> through JNI then parse to java

佐手、 提交于 2020-08-27 21:57:31
问题 Hi I want to secure my web url and app secret keys through Ndk, I want to create hashmap in app and also store key values statically then parse to java, I follow Stackoverflow answer like Create HashMap also JNI passing objects from C++ to Java some method deprecated from above link and didn't find any way to do this, I created HashMap but it giving me error #include <jni.h> extern "C" JNIEXPORT jobject Java_com_company_project_home_ui_MainActivity_getUrlMap( JNIEnv *env, jobject /* this */)

Can't call java methods from c++ wrapper in JNI

空扰寡人 提交于 2020-08-08 05:16:04
问题 I'm new in JNI and c++. I have some api that required shared pointer with some handler to subscribe on some messages. I can call required method in my handler in "main" c++ method, but when I call it from c++ wrapper I get JVM error and my application crash. My native method is next: public native int subscribe(Handler handler); Java Handler class: public class Handler { public void call(String m1, String m2) { System.out.println("call: " + m1 + " " + m2); } } JNI implementation: JNIEXPORT

CMake JNI error

北城余情 提交于 2020-08-04 09:33:08
问题 I've written a binding C++ class that calls java from C++. I am trying to compile the binding class using CMake (because the tool that will use the binding class uses CMake). However I receive the following error: CMakeFiles/JNIWrapper.dir/JNIWrapper.cpp.o: In function `createVM(JavaVM_**)': JNIWrapper.cpp:(.text+0x52): undefined reference to `JNI_CreateJavaVM' collect2: ld returned 1 exit status make[2]: *** [JNIWrapper] Error 1 make[1]: *** [CMakeFiles/JNIWrapper.dir/all] Error 2 make: ***