Hi,
I'm trying to increase the sharpness & darkness of shipping labels printed with my ZD420 printer via an Android app.
I found sample code for this in the docs here (http://techdocs.zebra.com/link-os/2-14/android/) but when I try it, my code crashes when I call ZebraPrinterFactory.getLinkOsPrinter(connection). The error I get is:
"java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper;"
As far as i've been able to discern this error can occur when the correct gradle dependencies for a project aren't configured. I'm importing the ZSDK library in my gradle build as shown below, and Android Studio clearly imports the correct Zebra lib classes into my Activity where my invocation of the getLinkOsPrinter functions lives, so i'm not sure why the NoClassDefFoundError is happening at runtime.
What do I have to do to get my code to run while using these classes?
Activity.kt
.....................................................................................................................................................................................................................................................................
private var printer: ZebraPrinter? = null
private var printerUSBConnection: Connection? = null
printerUSBConnection = discoveredPrinterUsb.connection
printerUSBConnection?.open()
printer = ZebraPrinterFactory.getInstance(PrinterLanguage.ZPL, printerUSBConnection)
setPrintLanguage(printerUSBConnection)
//test label darkening settings
val linkOsPrinter: ZebraPrinterLinkOs = ZebraPrinterFactory.getLinkOsPrinter(printerUSBConnection) //RUNTIME CRASH HERE
val availableSettings: Set = linkOsPrinter.availableSettings
.....................................................................................................................................................................................................................................................................
build.gradle
.....................................................................................................................................................................................................................................................................
dependencies {
implementation files('libs/ZSDK_ANDROID_API.jar')
}
.....................................................................................................................................................................................................................................................................
Logcat Error
.....................................................................................................................................................................................................................................................................
2019-05-29 10:46:01.884 16088-16088/com.nu.rms.packing E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nu.rms.packing, PID: 16088
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper;
at com.zebra.sdk.settings.internal.JsonHelper.isValidJson(Unknown Source)
at com.zebra.sdk.settings.internal.JsonValidator.isResponseComplete(Unknown Source)
at com.zebra.sdk.comm.ConnectionA.sendAndWaitForValidResponse(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.getDiscoMapViaJson(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.queryVersionInfoOverSingleChannel(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.queryVersionNumber(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.obtainVersion(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.createLinkOsPrinterFromStandardConnection(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.create(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.create(Unknown Source)
at com.zebra.sdk.printer.internal.ZebraPrinterFactoryHelper.getLinkOsPrinter(Unknown Source)
at com.zebra.sdk.printer.ZebraPrinterFactory.getLinkOsPrinter(Unknown Source)
at com.nu.rms.packing.ui.activity.PackingActivity$mUsbReceiver$1.onReceive(PackingActivity.kt:217)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1122)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.fasterxml.jackson.databind.ObjectMapper" on path: DexPathList[[zip file "/data/app/com.nu.rms.packing-2/base.apk"],nativeLibraryDirectories=[/data/app/com.nu.rms.packing-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.zebra.sdk.settings.internal.JsonHelper.isValidJson(Unknown Source)
at com.zebra.sdk.settings.internal.JsonValidator.isResponseComplete(Unknown Source)
at com.zebra.sdk.comm.ConnectionA.sendAndWaitForValidResponse(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.getDiscoMapViaJson(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.queryVersionInfoOverSingleChannel(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.queryVersionNumber(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.obtainVersion(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.createLinkOsPrinterFromStandardConnection(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.create(Unknown Source)
at com.zebra.sdk.printer.internal.LinkOsPrinterCreatorSgdOrJson.create(Unknown Source)
at com.zebra.sdk.printer.internal.ZebraPrinterFactoryHelper.getLinkOsPrinter(Unknown Source)
at com.zebra.sdk.printer.ZebraPrinterFactory.getLinkOsPrinter(Unknown Source)
at com.nu.rms.packing.ui.activity.PackingActivity$mUsbReceiver$1.onReceive(PackingActivity.kt:217)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1122)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
.....................................................................................................................................................................................................................................................................
[Android] Increasing Label Darkness with ZD420: can't find ZebraPrinterLinkOs |
1 Replies
I know it has been a while since you posted this, but I just hit a similar issue and wanted to make sure the existing resolution is documented. While I was not trying to change any label properties, calling ZebraPrinterLinkOs.getLinkOsPrinter(Connection var0) resulted in the same crash you put above.
I was able to fix it by adding a dependency to my app's build.gradle for the following library: https://github.com/FasterXML/jackson
Specifically, I added compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'