vrwim
vrwim

Reputation: 14380

How to make shared logic usable for cross-platform native apps?

So I am currently using Xamarin for multi-platform mobile applications. I really like the way this works, and I want to improve my flow. My developers have said that they would be much faster when programming natively (i.e. Swift for iOS in XCode).

I have looked for a solution, where I can create a shared project and use it in native apps, but I have only found ways that involve programming in one language for all platforms.

Is there a way to create a shared project, which can be imported into a native application (or better, can be run together, like a shared project in Xamarin)?

The language for the shared code is not important, as long as it isn't slow.

Upvotes: 3

Views: 2174

Answers (3)

Jared
Jared

Reputation: 702

If the goal is to use truly native tooling, in their standard languages (meaning not Xamarin) and still share code between iOS and Android, this can be achieved by writing your non-UI code in C++.

Here's a very interesting article about how Dropbox does exactly this.

C++ is natively supported on iOS and it is very easy to interface between Objective-C and C++ using Objective-C++.

On Android, calling into C++ can be done through the NDK, which reportedly is not a pleasure to use. Dropbox found Google’s meta-build system gyp to work reasonably well. In addition, the Java Native Interface is a pain you have to accept. But none of these issues is a roadblock, and Steven expressed hope that Google or the community will build better tooling support over time.

And here's a simple example of how to do this from another StackOverflow post

Upvotes: 1

Wosi
Wosi

Reputation: 45361

My developers have said that they would be much faster when programming natively (i.e. Swift for iOS in XCode)

Swift can be used natively for iOS apps. RemObjects' Silver is supposed to make Swift ready for Android and .NET. I've never tested it. Try it out, it's free.

RoboVM can be used to write iOS apps in Java. I didn't try it out either.

Language mixing with Xamarin

In case you want to mix Swift code with C# code using Xamarin then you can bind Objective-C compatible Swift code and use it in iOS projects only. You are not able to execute Swift code on Android or Windows Phone! It's not possible to write platform independent business logic in Swift and and use it in a shared library or PCL with Xamarin.

You face the same restrictions for Java code on Android: You can bind JARs and use them in a Xamarin.Android project but you cannot use them on iOS or Windows Phone.

You are also unable to execute C# code in a Swift based app on iOS or in a Java based app on Android.

Upvotes: 4

Jason
Jason

Reputation: 89214

You can use native code in Xamarin apps via Binding Libraries. You cannot use Xamarin libraries in native apps.

Upvotes: 1

Related Questions