0 Replies Latest reply on Mar 8, 2018 6:08 AM by Thomas Jones

    Android Zebra SDK 2.2.4.0 - Dex Failure because of Gson

    Thomas Jones

      Hello,

      I'm currently working with an app that was using the Android Zebra SDK 2.0.8.0 and would like to update to the latest (2.2.4.0). However, I now get a build error, showing a failure in the dexing of the apk:

      * What went wrong:

      Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

      > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

      I've tracked this down to the fact that my project includes the Gson library, version 2.8.1. I opened the contents of the ZebraSDK AAR and see that Gson 2.2.4 is being bundled in the libs folder. I suspect this is overriding the version of Gson I'm specifying in my gradle file due to a particular feature of the newer version now resulting in a compile error when including in the new Zebra SDK :

      > Task :app:compileDebugJavaWithJavac

      /.../ZebraTest/app/src/main/java/com/sample/zebratest/JsonModel.java:9: error: cannot find symbol

          @SerializedName(value="name1", alternate={"name_1"})

      As you see here, the 'alternate' attribute of the SerializeName annotation is no longer available. Ordinarily if the SDK was a Maven dependency, one could simply add exclusions for the particular module and the version specified in the gradle file would take precedence, such as :

      implementation('com.zebra.scannercontrol:barcode_scanner_library_v2.2.4.0@aar', {

        exclude group: 'com.google.code', module: 'gson'
      })

      However, I don't think it's possible to add exclusions on local file dependencies.

       

      So far I've tried a few things:

      1) Created a module from the AAR and attempted to exclude with library syntax, but it resulted in the same errors:

      implementation (project(":barcode_scanner_library"), {

        exclude group: 'com.google.code', module: 'gson'
      })

       

      2) I've created a new version of the .aar by unzipping the existing aar and removing the gson jar file, and zipping it back up, but this also did not work - the app now fails to find any of the dependencies specified of the SDK, perhaps I've created the aar incorrectly.

       

      I'm at a loss as to what to do next. Does anyone use the 2.2.4.0 Zebra SDK with newer versions of Gson successfully? Any help is appreciated.