uni-app 原生插件开发时 com.alibaba:fastjson:1.1.46.android 报错解决方法
Andorid Studio 报的错误03-12 00:55:09.156 7476-7476/com.example.pdaplugin E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.example.pdaplugin, PID: 7476java.lang.NoClassDefFoundError: Failed resolution
·
Andorid Studio 报的错误
03-12 00:55:09.156 7476-7476/com.example.pdaplugin E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pdaplugin, PID: 7476
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/alibaba/fastjson/JSONObject;
at com.lrp.serialport.UniSerialPort.initScanner(UniSerialPort.java:27)
at com.example.pdaplugin.Main.onCreate(Main.java:17)
at android.app.Activity.performCreate(Activity.java:6266)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:772)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.alibaba.fastjson.JSONObject" on path: DexPathList[[zip file "/data/app/com.example.pdaplugin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.pdaplugin-2/lib/arm, /data/app/com.example.pdaplugin-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.lrp.serialport.UniSerialPort.initScanner(UniSerialPort.java:27)
at com.example.pdaplugin.Main.onCreate(Main.java:17)
at android.app.Activity.performCreate(Activity.java:6266)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:772)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
Suppressed: java.lang.ClassNotFoundException: com.alibaba.fastjson.JSONObject
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
解决方法
将 compileOnly 'com.alibaba:fastjson:1.1.46.android'
改为 api 'com.alibaba:fastjson:1.1.46.android'
即不会报错了。
更多推荐
已为社区贡献4条内容
所有评论(0)