SweetBlue & Xamarin

  • We have a one-off customer who uses Xamarin to develop their application. My company provides a library (AAR) to this company. Our core application is pure Java for Android and Objective-C for iOS. The library we created for this customer depends on the SweetBlue AAR internally for managing BLE activity. SweetBlue is not exposed externally. We are having trouble creating "Xamarin Bindings" for the SweetBlue library that will allow it to be packaged into the Xamarin app so that our library has access to the SweetBlue API. Has anyone integrated SweetBlue with Xamarin with success? The customer is currently recommending that we re-write our library using a BLE library that is proven to be Xamarin compatible. Based on our success with SweetBlue, I would like to determine if making SweetBlue Xamarin compatible is an option. Again, I don't need any parts of SweetBlue to be exposed to the Xamarin C# codebase. I just need to find a way to expose the SweetBlue library to our library within the Xamarin framework. Any help or advice/recommendations would be appreciated.



  • I'm pretty sure there are people who are using SweetBlue with Xamarin. About 3 years ago, we started making a Xamarin port, but unfortunately, it never went anywhere. It's certainly possible, though I haven't looked at Xamarin since that time.

  • @ryanbis can you tell me if you compile the SweetBlue library using Java 1.8 and the version of Gradle that you use? I am working through the compatibility of the Java 1.8 features and Xamarin and believe that the Java 1.8 lambda expressions are causing the problems I am seeing. There are some tools to make Java 1.8 code compatible with Java 1.7 but some of them reference certain Gradle versions. Anything you can share about the SweetBlue build environment may prove helpful.



  • Yes, SweetBlue is using Java 8. As for the gradle version, it depends on the version. We usually try to keep on top of the latest. In 3.1.0, we're using gradle plugin version 3.4.0, and gradle itself is on 5.1.1.

  • @ryanbis Super. Thanks for the info. I am using the same versions for my library build as well.

  • We are using sweetblue v2 with xamarin. I needed to basically create a java wrapper interface around the bledevice methods which required callbacks/listeners. The bindings compilation had issues with the generic type java features being used with the listeners, so I just call to my java wrapper object from c# which has simple listeners and the binding generation has no issues with.
    I've attached our wrapper's source code for you to use, it filters the scans without needing to call back into c# too which was a huge performance improvement.sweetbluewrapper