title: How to call java class and its method from JNI android?
body: <p>I want to call inner java class in my cpp class.</p>
  
  <p>here is my simple java class(Activity)</p>
  
  <pre><code> public class MainActivity extends AppCompatActivity {
  
      static {
  
          System.loadLibrary("myLibrary");
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Toast.makeText(this, "" + stringFromJNI(), Toast.LENGTH_SHORT).show();
          checkAES();
          checkRSA();
          invokeclass();
          Log.d("Gajanand", "onCreate: "+invokeclass());
      }
     public native String stringFromJNI();
  
      public native int checkRSA();
  
      public native void checkAES();
  
      public native int invokeclass();
  
      public static class bar {
          public static int timesTen(int input){
              return input * 10;
          }
      }
  
  }
  </code></pre>
  
  <p>and my cpp class is like below</p>
  
  <pre><code>#include&lt;jni.h&gt;
  #include &lt;string&gt;
  
  #include &lt;android/log.h&gt;
  #include &lt;openssl/rsa.h&gt;
  #include &lt;openssl/aes.h&gt;
  
  
  extern "C"
  JNIEXPORT jstring  JNICALL
  Java_com_manvish_bwssb_Activities_MainActivity_stringFromJNI(
          JNIEnv *env,
          jobject /* this */) {
      std::string hello = "Hello from C++";
      return env-&gt;NewStringUTF(hello.c_str());
  }
  #define nr_bits 2048
  
  extern "C"
  JNIEXPORT int JNICALL
    Java_com_manvish_bwssb_Activities_MainActivity_checkRSA(JNIEnv *env, jobject /* this */) {
      RSA *rsa = RSA_generate_key(nr_bits, 65537, NULL, NULL);
      return 0;
  }
  
  static const unsigned char key[] = {
          0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
          0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
          0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
          0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  };
  
  extern "C"
  void Java_com_manvish_bwssb_Activities_MainActivity_checkAES(JNIEnv *env, jobject /* this */) {
  
      unsigned char text[] = "Kishan of Nanda";
      unsigned char out[80];
      unsigned char decout[80];
  
      AES_KEY wctx;
  
      AES_set_encrypt_key(key, 128, &amp;wctx);
      AES_encrypt(text, out, &amp;wctx);
      printf("encryp data = %s\n", out);
      __android_log_print(ANDROID_LOG_DEBUG, "Gajanand", "Encrypted data: %s\n", out);
  
      AES_set_decrypt_key(key, 128, &amp;wctx);
      AES_decrypt(out, decout, &amp;wctx);
  
      printf(" Decrypted o/p: %s \n", decout);
      __android_log_print(ANDROID_LOG_DEBUG, "Gajanand", "Decrypted data: %s\n", decout);
  }
  extern "C"
  JNIEXPORT int JNICALL
   Java_com_manvish_bwssb_Activities_MainActivity_invokeclass(JNIEnv *env)
  {
      jclass myClass = env-&gt;FindClass("bar");
      jmethodID mid = env-&gt;GetStaticMethodID(myClass, "timesTen", "(I)I");
      jint hundred = env-&gt;CallStaticIntMethod(myClass, mid, (jint)10);
      return hundred;
  }
  </code></pre>
  
  <p>what happening in my class is checkRSA() and checkAES() is calling repeatedly. i am not getting why only these two methods calling repeatedly.but invokeclass() method is not calling at all.is this correct way to call java class or is there any other method.? and another problem in my app is building app taking more than 3 minutes.help me to solve these both issue.</p>