Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to make JNI call from c++ to java in android lollipop using jni #649

Open
GoogleCodeExporter opened this issue Jul 29, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Hi,

I am making a library app which detects native crashes in android using
google breakpad. Whenever my main app has a native crash, breakpad invokes
the following callback. From this callback, I need to call a static void
method in a java class using JNI.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----

*bool breakpad_callback(const google_breakpad::MinidumpDescriptor& descriptor, 
void* context, bool succeeded) {

JNIEnv* env = NULL;

if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
{
     if(isDebug)
         LOGI("Failed to get the environment");
     return false;
}

if(isDebug)
     LOGI("attaching thread ...");
vm->AttachCurrentThread(&env, NULL);

if(isDebug)
     LOGI("handle exception");

  ExceptionHandlerClass = (jclass)env->NewGlobalRef(env->FindClass("com/abc/Myclass"));
         if (ExceptionHandlerClass == NULL)
             LOGE("Could not find java class");

  ExceptionHandlerMethod = env->GetStaticMethodID(ExceptionHandlerClass, "handleException", "()V");
         if (ExceptionHandlerMethod == NULL)
             LOGE("Could not bind exception handler method");

// handle exception
env->CallStaticVoidMethod(ExceptionHandlerClass, ExceptionHandlerMethod);

if(env->ExceptionCheck()) {
     LOGI("got exception");
     env->ExceptionDescribe();
}


if(isDebug)
     LOGI("exception handled");
}*


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------

This is my java method:


*package com.abc;
public class Myclass {
   public static void handleException() {
      System.out.println("inside handle exception");
   }
}*


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------


This used to work fine before Android 5.0. But in Lollipop, I am not able to 
call my java method as I am not able to see 'inside handle exception log on 
Logcat console.

Here are the log msgs I see on logcat:

*12-01 13:57:46.617: I/AACRNative(1617): attaching thread ...
12-01 13:57:46.617: I/AACRNative(1617): handle exception
12-01 13:57:46.619: I/AACRNative(1617): got exception
12-01 13:57:46.620: W/art(1617): JNI WARNING: java.lang.StackOverflowError 
thrown while calling printStackTrace
12-01 13:57:46.620: I/AACRNative(1617): exception handled*


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------


Any help would be really appreciable.


Original issue reported on code.google.com by [email protected] on 14 Apr 2015 at 4:25

@GoogleCodeExporter
Copy link
Author

Hi,

I have the exact same error, and can verify that it does work on Andoid 4.4, 
but fails on Android 5.1.

On my native side I can do everything, except doing Java calls.

Original comment by [email protected] on 23 Apr 2015 at 12:38

@GoogleCodeExporter
Copy link
Author

I have solved this problem. You can create a new thread in the method 
"breakpad_callback" and then make JNI call from in the created thread. It will 
be work. Good Luck.

Original comment by [email protected] on 24 Apr 2015 at 2:03

@GoogleCodeExporter
Copy link
Author

Your solution works like a charm, thanks!

Original comment by [email protected] on 24 Apr 2015 at 7:19

@GoogleCodeExporter
Copy link
Author

Hi,

I have the same problem. Your solution really save my time. But I also found 
google breakpad can not dump the crash information on Android lollipop. The dmp 
files I got
are all empty. Do you encounter this problem? This is not true for Android 4.*.
Thanks. 

Original comment by [email protected] on 4 Jun 2015 at 9:37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant