Third-party libraries are great! They cut down on the development time significantly by allowing developers to not worry about building certain things, like a custom UI control or client service.
The Java ecosystem includes a diverse and immense collection of components. However, this isn’t a deal breaker, many of these components can be used to reduce the time it takes to develop an Android mobile application.
So I’ll introduce you an overview of some of the ways that developers can use these existing Java components to improve their Android mobile app experience with Xamarin Studio creating binding projects.
One important distinction to be made is that it may be in your best interest to convert a particular library to C# and Xamarin.Android, rather than bind it. There are certain advantages to each approach, as well as particular circumstances when each technique is particularly useful!
Binding:
-Little to no Java knowledge-Quick and straightforward-Less customizationConverting:
-Java knowledge-Tedious-More customizationSometimes in larger libraries, things can get complicated really quickly, converting it is harder and it’s required to have an extensive knowledge of how does the library work. In these cases, it would be more convenient to focus on binding instead on converting, it can be done in little time, and especially because the process is pretty reproducible once you get it down.
A binding is just a simply wrapper class (known as a Managed Callable Wrapper), which allows a .NET application to interop with non-.NET technology; in other words, to reproduce libraries in C# in a minimal amount of time without really any Java knowledge. In this case, it allows a Xamarin.Android mobile application to call a Java class or interface from C#.
This technique is an automated, declarative approach to binding Java libraries. It involves using either Xamarin Studio or a Visual Studio project type that is provided by Xamarin.Android: the Java Bindings Library. You only have to include a .java and .jar code within your app. To successfully create these bindings, a Java Bindings Library may still require some manual modifications.
You need to have in mind which classes or interfaces you’ll need to use in your mobile application. Sometimes the compiler might have trouble binding it and you have to fix like thousand errors (in you plan to convert a whole complex library, of course) So my recommendation is just bind those libraries that you really need.
Maybe the owner of the library does not provide documentation of the java classes, so you can use this helpful tool called JD-GUI, which is a Java Decompiler and you can download it from here: http://bit.ly/1alkUOW
As I said lastly, to successfully binding may still require some manual modifications. For example, there’s a confliction between System.Object and Java.Lang.Object namespaces, the .NET conventions are a quite different from Java conversions (interfaces start with “i”, PascalCased members, etc.) and make public those classes, methods, field access you’re going to need.
Before getting startet imagine that you have to implement a chat using a protocol like XMPP which is only available for Java. Smack is the name of a complex Java library which implements standards of XMPP created by Ignition and is your only reliable resource on internet.
So, you can download it from here: http://bit.ly/1jqsbPt
Ok, so we are ready to start coding and see how can we make the development faster. In the next part we will create an Android Java Binding project from scratch.
Feel free to leave any coments and keep tuned for the next part!
Oscar Fimbres is a Computer Science student. He has been involved in ASP.NET MVC and Windows RT projects. He currently works as Xamarin Mobile Developer at iTexico. Also he is a Microsoft Student Partner since 2011 spreading the word about Microsoft Technologies in his student life.
No comments:
Post a Comment