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

373 views
Skip to first unread message

Prakhar Agrawal

unread,
Dec 1, 2014, 8:07:00 AM12/1/14
to andro...@googlegroups.com
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.

Thanks,
Prakhar Agrawal

Yu Yezhong

unread,
Mar 10, 2015, 5:30:47 AM3/10/15
to andro...@googlegroups.com
Hi Prakhar Agrawal,

Have you resolved this problem ?

Thanks.

Andreas Gampe

unread,
Apr 1, 2015, 1:08:40 PM4/1/15
to andro...@googlegroups.com
Bug has been filed at https://code.google.com/p/android/issues/detail?id=162663


There's an answer there. Please try and report back on the bug tracker.
Reply all
Reply to author
Forward
0 new messages