Develop cross-platform library for android and ios/

Can i develop library with using MOS which will be work on android and ios?

Hi,

yes. You just need to make sure to only use APIs that are available on both for Android and for iOS. This includes the standard Java classes (java.*, and very few android ones like android.util.Log).

The current best practice is to only rely on java.* and other non-Android specific Java libraries for your cross-platform library.

If you need to access platform-specific functionality from your library, then you should create an interface for it:

pubic interface PlatformSpecificFeature {

   public void useFeature();
}

And create Android and iOS implementations of this interface. As a working example, you can look at libgdx which is a Game Engine supporting many different target platforms. They use a similar strategy to abstract away platform differences.

Best Regards,
Gergely

Thanks, but how i can build static or shared library for ios? I read in this topik Link that is not available.

You don`t need static or shared libraries in order to write portable java code.
You declare platform independent code on one module, platform implementation in another module and then you link-and-compile all together using MOE into one executable.

For example our project supports the following platforms: MOE, RoboVM, GWT, TeaVM and Android.

That is about something different: it is about packaging the whole Java app + the MOE runtime into a single shared library to be used in a native iOS app. It is not about cross-platform libraries.

I assumed that you wanted to create a Java library that you wanted to use on Android and iOS. This is possible with MOE. Is this what you need?

About the linked feature:

The dynamic framework, supported by RoboVM is not possible, but it is also a bad design (I described in the linked forum), because if you want to use 2 java libraries that were packaged into such frameworks, the 2 VMs could clash at runtime.

MOE supports a better solution, starting with MOE 1.3. You can take any Xcode project, and add MOE to it as an extension very similar to how you can add CocoaPods to any Xcode project. Then you can add any number of Java libraries to MOE, and those will be compiled into a single binary, using a single VM into your iOS app.

Best Regards,
Gergely

PS: I just saw that @pkirill already answered, but I am going to post anyway :slight_smile:

I want to build cross-platform lib which others developers might using in their ios or android apllications.

And do you want to build this lib in Java (or other JVM language), or C/C++?

If you want to use Java, then you can build it as a Java library, and package it as a jar. You can even distribute it using Maven Central / JCenter, so they just need to add a Maven dependency in build.gradle.

An example for a cross-platform project is the Calculator sample app: It has an android and ios version + a common module, that is cross-platform. This common module could be distributed as a separate Java library.

Best Regards,
Gergely

you can explain more about developing a cross-platform library and how???

which type of library and how