java.lang.NoSuchMethodError: no static or non-static method 解决方法

最近在调试JNI的时候报了一个莫名其妙的错误,纠结了很久,现象是同一种类型的函数可以注册成功,不同类型的就会抛出一项异常:

E AndroidRuntime: java.lang.NoSuchMethodError: no static or non-static method "Lcom/sprd/validationtools/phasecheckjni/PhaseCheckJNI;.eng_writephasecheck(III)I"
E AndroidRuntime: at java.lang.Runtime.nativeLoad(Native Method)
E AndroidRuntime: at java.lang.Runtime.doLoad(Runtime.java:421)
E AndroidRuntime: at java.lang.Runtime.loadLibrary(Runtime.java:362)
E AndroidRuntime: at java.lang.System.loadLibrary(System.java:526)
E AndroidRuntime: at com.sprd.validationtools.phasecheckjni.PhaseCheckJNI.(PhaseCheckJNI.java:6)
E AndroidRuntime: at com.sprd.validationtools.PhaseCheckParse.(PhaseCheckParse.java:66)
E AndroidRuntime: at com.sprd.validationtools.ValidationToolsMainActivity.onCreate(ValidationToolsMainActivity.java:126)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5258)
E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1099)
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2239)
E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5372)
E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:970)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)


最后发现这是由于编译器优化引起的,需要在Android.mk里面加入如下属性即可:

LOCAL_PROGUARD_ENABLED:= disabled
问题解决~~

结论:Android jni中慎用Proguard

你可能感兴趣的:(android开发)