0

I have a problem to send data from java to my ndk the problem is that i have 3 files which is inject.cpp, inject.h and inject_main.cpp all this 3 files are converting to 1 library after compiling the app with the name injectcm.so.

In inject.cpp I have my c++ codes and in inject_main.cpp I'm calling the methods of inject.cpp and now I'm trying to send an integer from java to inject.cpp with this method

java:

   static {
        System.loadLibrary("injectvm");
    }

    public native int Calculate(int num);

but in this way I can not add like this code to my inject.cpp

extern "C"
JNIEXPORT void JNICALL
Java_com_example_esp_MainActivity_Calculate (JNIEnv *env, jobject) {
    __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "hello");
  
}

but this method can not work with my code is there any other way either this method to send string to ndk?

Source code I use: ---but with my codes I use it because I can access to kernel with this source https://github.com/Chainfire/injectvm-binderjack

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Are you building the library with Android NDK? If this is correct `System.loadLibrary("injectvm");` then the library should be called `libinjectvm.so`. Then use the Inspect APK from Android Studio to check it has been packed into the APK. If it is still not working attach the LogCat output to your questions (just the part where it fails to call your library function). – Richard Critten Oct 29 '19 at 21:41
  • You haven't shown us any error messages, but `Java_com_example_esp_MainActivity_Calculate (JNIEnv *env, jobject)` is obviously not correct since `Calculate` is declared as taking an `int` argument on the Java side. And you also haven't shown us enough of the Java code to be able to determine if the correct package name and class name was used. – Michael Oct 29 '19 at 21:45
  • Either [follow the documentation](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html), or use a tool like `javah` to [generate the function declarations for you](https://stackoverflow.com/questions/21663423/generating-header-file-with-jni-using-javah). – Michael Oct 29 '19 at 21:47
  • https://github.com/Chainfire/injectvm-binderjack iam using this sourcecode – Muhamad Kheder Oct 29 '19 at 22:23

0 Answers0