Android Realm插件导致ClassNotFoundException

时间:2017-08-01 15:12:17

标签: android realm classnotfoundexception

我和我的团队正在开发一个简单的Android应用程序,它使用三个外部库,加载到'libs'目录中,将命令发送到USB打印机。

这些库工作正常,但是当我们尝试集成Realm插件时,它们就会停止工作。

你知道为什么会这样吗?如果您需要进一步的信息,请告诉我。

步骤:

  • 在项目 build.gradle 中添加classpath "io.realm:realm-gradle-plugin:3.5.0",一切仍然可以正常工作

  • 在模块 build.gradle 中添加apply plugin: 'realm-android',外部库停止工作

技术信息:

Android Studio for Mac: 2.3.3
Gradle version: 2.3.3
compileSdkVersion: 25
buildToolsVersion: 25.0.3
minSdkVersion: 19
targetSdkVersion: 25

崩溃日志:

08-01 16:41:51.797 18080-18080/it.apptoyou.android.taxrefund W/System.err: java.lang.ClassNotFoundException: com.common.sdk.printer.UsbPrinterManager
08-01 16:41:51.797 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.Class.classForName(Native Method)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.Class.forName(Class.java:309)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.Class.forName(Class.java:273)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at com.telpo.tps550.api.printer.UsbThermalPrinter.start(UsbThermalPrinter.java:126)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at it.apptoyou.android.taxrefund.controllers.utils.PrinterManager.setupPrinter(PrinterManager.java:59)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at it.apptoyou.android.taxrefund.App.onCreate(App.java:42)
08-01 16:41:51.798 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.app.ActivityThread.access$1500(ActivityThread.java:151)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.os.Looper.loop(Looper.java:135)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:925)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:720)
08-01 16:41:51.799 18080-18080/it.apptoyou.android.taxrefund W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.common.sdk.printer.UsbPrinterManager" on path: DexPathList[[zip file "/data/app/it.apptoyou.android.taxrefund-2/base.apk"],nativeLibraryDirectories=[/data/app/it.apptoyou.android.taxrefund-2/lib/arm, /vendor/lib, /system/lib]]
08-01 16:41:51.800 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-01 16:41:51.800 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-01 16:41:51.800 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-01 16:41:51.800 18080-18080/it.apptoyou.android.taxrefund W/System.err:  ... 17 more
08-01 16:41:51.800 18080-18080/it.apptoyou.android.taxrefund W/System.err:  Suppressed: java.lang.ClassNotFoundException: com.common.sdk.printer.UsbPrinterManager
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.Class.classForName(Native Method)
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:      ... 18 more
08-01 16:41:51.801 18080-18080/it.apptoyou.android.taxrefund W/System.err:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

1 个答案:

答案 0 :(得分:1)

如果您使用的是Proguard,请确保proguard-rules.pro配置良好。