Cannot make JNI call from C ++ in java in android lollipop using jni

I am creating a library application that detects a malfunction in android using google breakpad. Whenever my main application has its own crash, breakpad calls the next callback. From this callback, I need to call the static void method in the 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 worked fine until Android 5.0. But in Lollipop I cannot call my java method, because I cannot see the "in handle exception" log in the Logcat console.

Here are the log messages that 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 

Can someone please help me with this?

+5
source share
3 answers

Known issue , it mentions some workaround, but it has not yet been fixed. ART uses an alternative stack for signal processing, which causes a problem.

0
source
 JNI WARNING: java.lang.StackOverflowError thrown while calling printStackTrace 

Your application consumes too much stack.

0
source

You can create a new thread in the breakpad_callback method and then make a JNI call in the thread. He will work.

0
source

Source: https://habr.com/ru/post/1208015/


All Articles