Asiri Liyana Arachchi
Asiri Liyana Arachchi

Reputation: 2673

Can I use a Java library in an iOS app using Cordova?

I would like to use the Ionic or other cross-platform framework to build a mobile app. In this app I would like to use a Java library. From what I understand, I can use this Java library in my hybrid app if I write a Cordova wrapper for the library. But I have not been able to find a way to use the Java library on iOS. Is this possible?

Upvotes: 1

Views: 924

Answers (2)

Shai Almog
Shai Almog

Reputation: 52760

You can use Java code if you use Codename One's Cordova compatibility for portability.

Notice you can't use a binary jar "as is" but you can use Java source code which will work natively on iOS.

Upvotes: 1

Dexter
Dexter

Reputation: 2472

You can't, iOS apps don't understand Java, even if you write a Cordova plugin. Is there no iOS alternative of the library you want to use?

Using Cordova you could build a plugin that uses the library you want to use on Android and use a different library on iOS. In your Ionic app, if the plugin is well written, you will be able to call the same function and the plugin will handle the rest.

Regarding this:

I've found that in android once you wirte a Cordova wrapper for the library it can be used within the app even though I don't really understand what it really means.

Cordova allows you to call native functions using JavaScript, so without Cordova you won't be able to use the Java library, but by building a plugin using Cordova you can. Here is a tutorial on how to create a Cordova plugin and here is another. I also recommend looking at existing Cordova plugins to see how it is done. If you share the library, we may also be able to help you create the plugin.

Upvotes: 1

Related Questions