0

I have writing Aar library file, this needs to be linked with the Android APP which has Asynchronous calls to this library using JNI Call. These JNI Calls needs to be invoke the corresponding Functions on the Class file.

Android Asynchronous calls -> c++ JNI -> library(aar)

Here aar file has JNI Reception and calls to the Android Class file. From JNI we need to pass the context to the Android Class file.

Control is coming to the JNIClass_Initialize() where the context and jenv_obj being passed.
From Here not able to find class, as this Class was not initiated.

How to initiate the Class file from JNI Interface.

The following is the code:

Getting

int JNIClass_Initialize(
        void *context
        , void *jenv_obj
) { 

//Not able to initiate or invoke Class functions.

  jclass cls = (jniEnvVal.env)->FindClass("ae/info/TestReader");

 //Here it is crashing - As not getting the class 
  jmethodID initFun1= (jniEnvVal.env)->GetStaticMethodID(cls, "Init_func", "(Landroid/content/Context;)I");


  jint retVal = (jniEnvVal.env)->CallStaticIntMethod(cls, initFun1= ,context);
}

public class TestReader{

    Init_func(Context cnt) {
    //Process it
    }
}

Thanks for any Help.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • The easiest solution is to do all `FindClass` calls in `JNI_OnLoad`, because there you know you'll have the right classloader. – Michael Feb 12 '20 at 07:36
  • 2
    Does this answer your question? [FindClass from any thread in Android JNI](https://stackoverflow.com/questions/13263340/findclass-from-any-thread-in-android-jni) – frogatto Feb 12 '20 at 08:34

0 Answers0