Android ndk No implementation found for native
http://www.drovik.com/ 2013-7-2 15:32:34 来源:www.drovik.com 点击:
Android NDK No implementation found for native
现象描述:
用ndk做android开发时,在Debug模式下,测试应用是正常的,在release新版本并用proguard混淆的时候就会抛出No implementation found for native的异常。Lcom/xx/xx/Tools;.glInitDecoder (I)I
07-02 13:48:29.309: W/dalvikvm(30195): threadid=18: thread exiting with uncaught exception (group=0x40a891f8)
07-02 13:48:29.319: E/AndroidRuntime(30195): FATAL EXCEPTION: Thread-563
07-02 13:48:29.319: E/AndroidRuntime(30195): java.lang.UnsatisfiedLinkError: glInitDecoder
07-02 13:48:29.319: E/AndroidRuntime(30195): at com.iped.ipcam.gui.UdtTools.glInitDecoder(Native Method)
07-02 13:48:29.319: E/AndroidRuntime(30195): at com.xx.xx.a.ab.run(Unknown Source)
07-02 13:48:29.319: E/AndroidRuntime(30195): at java.lang.Thread.run(Thread.java:856)
07-02 13:48:29.326: W/System.err(191): /data/system/carrierinfo.prop: open failed: ENOENT (No such file or directory)
07-02 13:48:29.326: E/ActivityManager(191): sendActivityStabilityInfo -> exception bw.write()java.io.IOException: Transport endpoint is not connected
问题解决:
从上面的堆栈可以看出,java层程序没有找到NDK层的方法,Debug模式下又是正常的。可见问题是由混淆所致。
具体的混淆配置文件如下:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-dontwarn android.support.v4.**
-dontwarn org.apache.harmony.**
-dontwarn com.sun.mail.**
-dontwarn javax.activation.**
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
网上对此问题的说法也很多。
比如:函数定义的时候加上JNIEXPORT;
再比如:重载jni_onload函数,在里面调用(*env)->RegisterNatives这个方法去export等等,尝试了几个方法都没有解决这个问题。
解决问题问题出现在红色字体部分:
用keepclasseswithmembers替换keepclasseswithmembernames就可以成功找到ndk层中的方法了。
- 相关文章
- Android的NDK开发—JNI数据结构之JNINativeMethod (266人浏览)
- Android-stagefright与opencore对比 (120人浏览)
- Android2.2、2.3、4.0 中如何使用GPU硬件加速原理 和游戏3D性 (351人浏览)
- android中的surface (364人浏览)
- android系统信息(内存、cpu、sd卡、电量、版本)获取 (539人浏览)
- Android ndk signal 4 (SIGILL), fault add (461人浏览)
- Android opengl es context lost when devi (261人浏览)
发表评论(0)