This website uses cookies to ensure you get the best experience. Learn More.
Binding Java and Swift libraries for Xamarin projects
Previously, we talked about how market is really fragmented right now because there isn’t any popular hybrid framework. We kept an eye on some of the most popular frameworks like React Native, Nativescript, Ionic2 and Xamarin. We did a prototype with Nativescript and it worked fine but we think that the use of native libraries with this technology isn’t mature enough. If you want to know how these frameworks work underneath and their pros and cons, read this article.
Since I started with hybrid frameworks, I have another point of view of how other developers work with other technology or language and also how I feel working outside my comfort zone. We usually work with Java for Android, Swift for iOS and this year we built a hybrid solution for our framework using JavaScript and CSS. But, we have never tried some cross-compile framework. So, we decided to give Xamarin a chance!
“We want to help people develop their apps easier and faster. Liferay Screens is our solution. Since 2017, you don’t have to choose between native and hybrid, you can use both at the same time!”
The team decided to implement a prototype in Xamarin, but we didn’t know this framework very well. So, first of all, we had to know what language we had to use, how it worked, and how we could use Liferay Screens using the native part, so we didn’t have to code everything again.
Xamarin has a lot of documentation and you have to read it at least twice, if not more, just to connect all the dots and realise what you’re doing. We need to know some things before starting:
When we took our first steps and wrote some C# code, we were prepared to start our binding library but…Surprise, surprise!
Officially, Xamarin does not support binding Swift libraries.
Ok, that’s awful, but it’s not the end of the world. Let’s investigate!
We talked with the community about binding Swift libraries and everybody seemed to be very lost. You would think that no one had done this before (some people in Objective-C, right, but not in Swift). I kept investigating and I found a post in StackOverflow related to what I wanted to do. This was really exciting and I did everything step by step to get my C# library. The post was moved to Medium: https://medium.com/@Flash3001/binding-swift-libraries-xamarin-ios-ff32adbc7c76
When we had our first draft of the library, with only two or three classes, we decided to test it. We created a new Xamarin project, installed the NuGet package and…It failed.
At this point, we read the documentation about error codes and binding troubleshooting. And we had to add this information to the previous one:
At that moment, we had everything we really needed to implement our library. So, we started the whole implementation:
.aar
.framework
x86
arm
sharpie bind
.h
ApiDefinitions.cs
StrucsAndEnums.cs
We worked hard and finally we created a binding library from our native one. This library is already in the NuGet website.
This was really amazing because we didn’t know anything about C#, nor Xamarin, nor binding a library and here we are, with our library released and ready to be used. Finally, we reached our goal and we created a library without implementing everything again. It was hard and it took almost 4 months but now everyone can use it and this is what we love most!
The steps to create a binding library are annoying and it’s very easy to get angry and not understand what’s going on, what’s the meaning of an error, why it’s not working and so on.
It may also help to investigate Xamarin.Android and Xamarin.iOS sample apps developed by Liferay. Both are good examples of how to use the Screenlets, Views (Android), and Themes (iOS):
If you want to read more about Liferay Screens for Xamarin, you can read our official documentation: https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/using-xamarin-with-liferay-screens
If you have any questions about how to install it or how to use it, just post it in our forums. We will gladly help you. And if you already have a binding library, share your experience with others.