JNI_OnLoad returned bad version (-1) 问题解决 proguard

添加jni时出现如下问题

log 如下

01-07 17:34:51.406 W/dalvikvm( 2032): JNI_OnLoad returned bad version (-1) in /system/lib/libengfetch_jni.so 0x423fcc30

01-07 17:34:51.406 D/wll     ( 2032): load libtesterstatus_jni error!
01-07 17:34:51.406 W/dalvikvm( 2032): No implementation found for native Lcom/huaqin/runtime/engtools/engfetch;.engf_writephasecheck:(II)V
01-07 17:34:51.406 D/AndroidRuntime( 2032): Shutting down VM
01-07 17:34:51.406 W/dalvikvm( 2032): threadid=1: thread exiting with uncaught exception (group=0x41cdc378)
01-07 17:34:51.406 I/        ( 2032): JNI_OnLoad
01-07 17:34:51.406 E/        ( 2032): RegisterNatives failed for 'com/huaqin/runtime/engtools/engfetch'
01-07 17:34:51.406 E/        ( 2032): ERROR: registerNatives failed
01-07 17:34:51.406 E/AndroidRuntime( 2032): FATAL EXCEPTION: main
01-07 17:34:51.406 E/AndroidRuntime( 2032): java.lang.UnsatisfiedLinkError: Native method not found: com.huaqin.runtime.engtools.engfetch.engf_writephasecheck:(II)V
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.huaqin.runtime.engtools.engfetch.engf_writephasecheck(Native Method)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.huaqin.runtime.engtools.engfetch.engwritephasecheck(engfetch.java:124)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.huaqin.runtime.RuntimeTestTesting.RuntimeTestTestingResultSave(RuntimeTestTesting.java:196)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.huaqin.runtime.RuntimeTestTesting.access$2000(RuntimeTestTesting.java:42)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.huaqin.runtime.RuntimeTestTesting$3.onReceive(RuntimeTestTesting.java:316)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at android.os.Handler.handleCallback(Handler.java:615)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at android.os.Looper.loop(Looper.java:137)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at android.app.ActivityThread.main(ActivityThread.java:4990)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:574)
01-07 17:34:51.406 E/AndroidRuntime( 2032): at dalvik.system.NativeStart.main(Native Method)

01-07 17:34:51.416 W/ActivityManager(  449):   Force finishing activity com.huaqin.runtime/.RuntimeTestTesting

.........

网上搜索可能是proguard问题引起的。

判断出在编译的时候系统做了优化,把无用的代码做了过滤(engf_writephasecheck )。好,那我就在编译时强制保留此方法,了解到Android系统编译是用ProGuard来进行代码优化和混淆工作的,OK,参照别的Android.mk文件加了参数:

   LOCAL_PROGUARD_FLAG_FILES := proguard.flags


又创建了proguard.flags文件,内容如下:

   -keep class com.huaqin.runtime.engtools.engfetch {static *;}
    }

保留engfentch所有的static方法.测试有效

参考 http://www.cnitblog.com/zouzheng/archive/2011/01/12/72639.html


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