Introduction
This page provides instructions to create a Xamarin binding library project for the Workpath SDK. It assumes the reader has working knowledge of Visual Studio and Xamarin.
General information about Xamarin’s java binding concept is provided here:
https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/
The instructions to bind an Android .aar are located here:
https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar
Setup Steps
- Create a new Bindings Library project (e.g. WorkpathBinding), starting with the Android Bindings Library template, as described in the ‘binding-an-aar’ reference.
- Once the project is created, the project template includes a Jars folder. Copy WorkpathLib.aar from the <Workpath SDK home folder>/Libraries to Jars folder in your project.
- Set the Build Action for WorkpathLib.aar to ‘LibraryProjectZip’.
- Edit Transforms/Metadata.xml to add:
<remove-node path="/api/package[starts-with (@name, 'com.hp.workpath.api') = false]" />
- Open the project Properties to configure the Applications settings. Set Android Class Parser to ‘class-parse’.
Note:
There is a known issue (https://developercommunity.visualstudio.com/content/problem/219595/class-parse-not-working-in-xamarin-android-binding.html), when setting ‘Android Class Parser’ via the Properties tab in Visual Studio 2017 versions. This issue manifests itself during the build, where the classes which inherit from or contain members of unresolvable types are skipped. A simple workaround of this issue is to add <AndroidClassParser>class-parse</AndroidClassParser> to your project file (.csproj) manually.
- Build your project, verify the output .dll is present in <Project Name>/bin/Debug/<Project Name>.dll.
Testing the Bindings Library
To consume the library, it must be added as a reference in your application project e.g. BindingTestApp.
- Right-Click the References node of your Application Project and select Add Reference...
- Select the binding project created earlier. e.g. WorkpathBinding
- Open the References node of your application project i.e. BindingTestApp to verify that the binding project i.e. WorkpathBinding reference is present.
- Double click the References to open it in the Object Browser. The content of the bindings library can be viewed:
- The method and types of the bindings library can be accessed, as any other C# methods and types.
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Initialize the Workpath Sdk
Workpath.Instance.Initialize(this);
// Workpath API access
ScanAttributes.MeBuilder meBuilder = new ScanAttributes.MeBuilder();
meBuilder.SetColorMode(ScanAttributes.ColorMode.Auto);
}
- Build and test your application!