android studio引入第三方库时报如下异常。
06-15 16:50:24.477 9497-9497/easemobim.test.com.easemobim E/AndroidRuntime: FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError: Couldn't load hyphenate_av from loader dalvik.system.PathClassLoader[dexPath=/data/app/easemobim.test.com.easemobim-1.apk,libraryPath=/data/app-lib/easemobim.test.com.easemobim-1]: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:365) at java.lang.System.loadLibrary(System.java:535) at com.hyphenate.chat.EMClient.loadLibrary(Unknown Source) at com.hyphenate.chat.EMClient.getInstance(Unknown Source) at easemobim.test.com.easemobim.MainActivity.onCreate(MainActivity.java:57) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5069) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) at dalvik.system.NativeStart.main(Native Method)
原因是android studio导入so文件没有编译到apk里面去,所以导致UnsatisfiedLinkError异常
打开app下的build.gradle,在android的标签下加入如下代码:
sourceSets { main { //jni库的调用会到资源文件夹下libs里面找so文件 jniLibs.srcDirs = ['libs'] } }
如:
android { ... ... sourceSets{ main{ jniLibs.srcDirs = ['libs'] } } ... ... }