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' 即不会报错了。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐