2017-11-25 174 views
0

我在本地方法执行SensorEventListener如下调用实例方法(使计算速度更快):无法从SensorEventListener本地JNI方法

public class GPSLogger extends Service 
    implements SensorEventListener { 

    public native void onSensorChanged(SensorEvent event); 
    public void startLocationUpdates() { // some code } 
} 

相对应的JNI实现被调用。但是我想从调用本地C代码startLocationUpdates()如下:

jclass objcls = (*env).GetObjectClass(obj); 
jmethodID methid = (*env).GetMethodID(objcls, "startLocationUpdates", "()V"); 
if (methid == NULL) 
    __android_log_write(ANDROID_LOG_ERROR, "[IFL]", "startLocationUpdates not found"); 
else 
    (*env).CallVoidMethod(obj, methid); 

在这种情况下methid为NULL。并且在亚行日志中有一个例外说

java.lang.NoSuchMethodError: no non-static method "Lmy/package/GPSLogger;.startLocationUpdates()V" 

什么可能是错的?我甚至尝试过将物品作为

jclass objcls = (*env).FindClass("my/package/GPSLogger"); 

但同样的问题。

回答

0

问题加入proguard的规则后解决(防止方法名的模糊处理):

-keep class my.package.GPSLogger { void startLocationUpdates(); }