Android NDK:调用 JNI GetMethodID 时出现未决异常 java.lang.ClassNotFoundException:未找到 class

Android NDK : JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class

我正在构建一个使用 NDK 和 Java 的 android 应用程序。 该应用程序在调试模式下运行良好。但是当我尝试构建发布 apk 时。它开始崩溃。 调试发布 APK 后,我发现

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class "example.motion.MotionDetectionReturnValue"

这是我的 .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);

我应该将它附加到 java 线程或类似的东西吗?我试过了,但我没有得到它

我错过了什么? ..谢谢

调试版本和发布版本之间的典型区别是后者打开了 ProGuard 混淆。这意味着许多 classes 和方法的名称会自动更改。大概,这就是classexample.motion.MotionDetectionReturnValue发生的事情。简单的解决方法是保留 JNI 中涉及的 classes 和方法的名称,而不混淆。参见 。

更先进的技术也可以保护这些 classes