Xamarin and the Zebra EMDK

Version 4

    Using Xamarin, developers can develop .Net applications and deploy them to Android devices.  Zebra does not provide a version of the EMDK that can be used directly in .Net applications targeted for Android devices, however using Xamarin there is a way it can be done.  Xamarin refers to the approach as Binding a Java Library.

     

    This article supplements the information contained in the Xamarin guide, to help developers create a binding to the EMDK.  With a few minor changes, one can follow the recipe provided by the guide, to create a binding to the EMDK jar file.

     

    The first difference between a binding to the EMDK and the one in the guide is that binding to the EMDK jar does not require any additional libraries, so instructions in the guide that refer to multiple libraries should be ignored.  The second difference, is the build action that is selected for the jar file included in the project.  The guide suggests that the build action should be "EmbeddedJar", however, using this setting results in a run-time error on the device when an application attempts to use the output from the binding project, see the logcat excerpt below.

     

    W/dalvikvm(23975): Class resolved by unexpected DEX: Lcom/symbol/barcodesample2/MainActivity;(0x41bf0548):0x5f04a000 ref [Lcom/symbo

    l/emdk/EMDKManager$EMDKListener;] Lcom/symbol/emdk/EMDKManager$EMDKListener;(0x41bf0548):0x5ef0f000

    W/dalvikvm(23975): (Lcom/symbol/barcodesample2/MainActivity; had used a different Lcom/symbol/emdk/EMDKManager$EMDKListener; during

    pre-verification)

     

    By selecting "InputJar' as the build action,  the run-time error can be eliminated, see the dialog below.

     

     

    The third and final difference between the procedure described here, and the procedure in the Xamarin guide is the inclusion of the EMDK jar file in any application that uses the output of the binding project.  The procedure described in the guide for including the jar file in the binding project should also be used by any application that uses the output of the binding project, that is, add the jar file to the project.  For applications using the output of the binding project, the build action should be set to "AndroidExternalJavaLibrary".

     

     

      If this step is not performed, building the application will fail with errors like the one shown below.

     

     

     

     

    The Xamarin guide contains a list of potential problems and suggested solutions, one such problem encountered is "missing C# type in generated output".  This can be resolved using the fix suggested by the  guide by including the remove-node directive, shown below, in the project's metadata.xml file. The values needed by "remove-node" were obtained by examining the file api.xml, see API Metadata Reference | Xamarin  for more information.

     

    <remove-node path="/api/package[@name='com.symbol.emdk.barcode']/interface[@name='BarcodeManager.ScannerConnectionListener']" />
    
    
    
    

     

    As described in the guide the two directives below should also be included in the metadata.xml.

     

    <attr path="/api/package[@name='com.symbol.emdk']" name="managedName">Symbol.Emdk</attr>
    <attr path="/api/package[@name='com.symbol.emdk.barcode']" name="managedName">Symbol.Emdk.Barcode</attr>
    
    
    
    

     

    Applications will then include lines like the ones below.

     

    using Symbol.Emdk;
    using Symbol.Emdk.Barcode;
    
    
    
    

     

    In the AssemblyInfo.cs for the application, the two lines below should be included.

     

    [assembly: UsesLibrary(Name = "com.symbol.emdk")]
    [assembly: UsesPermission(Name = "com.symbol.emdk.permission.EMDK")]
    
    
    

     

     

    By following the guide, and making the adjustments described and binding project was created and a simple C# scanning application was developed to confirm that this method can be used to access features of the EMDK in C# on an Android device.