Issue
I'm building an android app which uses NDK and Java. The app is working fine in debug mode. But when I try to build release apk. It starts crashing. After debugging the release APK I found that
JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class "example.motion.MotionDetectionReturnValue"
Here's the problem from my .cpp class
jobject object;
jmethodID constructor;
jclass cls;
cls = env->FindClass("example/motion/MotionDetectionReturnValue");
constructor = env->GetMethodID(cls, "<init>", "(DDDDDDD)V");
object = env->NewObject(cls, constructor, avg.x, avg.y, totalFraction, bottomRightFraction, bottomLeftFraction, topRightFraction, topLeftFraction);
should I attach it to java thread or something like that. I tried but I didn't get it
What am I missing ? ..Thanks
Solution
The typical difference between debug and release builds is that the latter turns on ProGuard obfuscation. This means that names of many classes and methods are automatically changed. Probably, this is what happened to the class example.motion.MotionDetectionReturnValue
. The easy fix is to keep the names of classes and methods that are involved in JNI, without obfuscation. See https://stackoverflow.com/a/24923279/192373.
More advanced techniques allow to protect these classes, too
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.