我用 android-serialport-api 这个类库操作串口,在原生应用下能够正常操作,但是用 Native.js 调用同样的方法就会报下面这个错误:
11-21 22:32:01.918: W/dalvikvm(2685): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Landroid_serialport_api/SerialPort;
异常堆栈:
11-22 21:06:16.916: E/AndroidRuntime(22375): FATAL EXCEPTION: main
11-22 21:06:16.916: E/AndroidRuntime(22375): Process: io.dcloud.HBuilder.Hello:pushservice, PID: 22375
11-22 21:06:16.916: E/AndroidRuntime(22375): java.lang.UnsatisfiedLinkError: Couldn't load serial_port from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.dcloud.HBuilder.Hello-1.apk"],nativeLibraryDirectories=[/data/app-lib/io.dcloud.HBuilder.Hello-1, /vendor/lib, /system/lib, /system/lib/arm]]]: findLibrary returned null
11-22 21:06:16.916: E/AndroidRuntime(22375): at java.lang.Runtime.loadLibrary(Runtime.java:358)
11-22 21:06:16.916: E/AndroidRuntime(22375): at java.lang.System.loadLibrary(System.java:526)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android_serialport_api.SerialPort.<clinit>(SerialPort.java:83)
11-22 21:06:16.916: E/AndroidRuntime(22375): at com.netstar.IDCardUtil.getUserName(IDCardUtil.java:45)
11-22 21:06:16.916: E/AndroidRuntime(22375): at com.netstar.ApplicationHelper$1.onClick(ApplicationHelper.java:38)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.view.View.performClick(View.java:4438)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.view.View$PerformClick.run(View.java:18431)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.os.Handler.handleCallback(Handler.java:733)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.os.Handler.dispatchMessage(Handler.java:95)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.os.Looper.loop(Looper.java:149)
11-22 21:06:16.916: E/AndroidRuntime(22375): at android.app.ActivityThread.main(ActivityThread.java:5045)
11-22 21:06:16.916: E/AndroidRuntime(22375): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 21:06:16.916: E/AndroidRuntime(22375): at java.lang.reflect.Method.invoke(Method.java:515)
11-22 21:06:16.916: E/AndroidRuntime(22375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
11-22 21:06:16.916: E/AndroidRuntime(22375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
11-22 21:06:16.916: E/AndroidRuntime(22375): at dalvik.system.NativeStart.main(Native Method)
不知道是什么问题,请大神们帮忙看看!
哈哈! 问题解决了!
起初我是在 /HBuilder-Hello/libs/armeabi 这个目录下添加相关的.so文件!
经过一番折腾 最后在/HBuilder-Hello/libs/armeabi-v7a, /HBuilder-Hello/libs/x86 目录下添加相关的.so文件就可以正常读写串口了!
3 个回复
sharpoo
哥啊,能给份读写串口代码不?
离线打包
qq:1346750276 共同学习
z***@163.com
请问你是将文件放进去直接调用的吗? 我这句 var SerialPortFinder=plus.android.importClass("android_serialport_api.SerialPortFinder");
一直报错