If you want to create a cross-platform application (iOS / Android / Web), it is best to use as much code as possible between these platforms. You could use something like PhoneGap / Cordova , but this is not always very popular. Event: the best PhoneGap app seems not native because it does not use its own user interface. Instead, the browser is embedded in its own user interface container.
I recommend using the project structure as follows:
- Myapp kernel
- MYAPP-ISN
- Myapp android
- Myapp web
The main project is shared between ios, android and the web project. You can write a main project in Java and use GWT to translate this code into JavaScript for a web project. There is nothing to do for an Android project, because Android uses Java. For your ios project, you can use J2Objc to pass the main Java code to Objective-C.
What is included in the main project?
Use interfaces and abstract base classes as well as factories as much as possible.
Conversations, reminders and contacts. We are also talking about the complex task of network management and offline synchronization, when the application is used offline, reminders are created and emails are sent. This is an application to save all this and launch it on the Internet when the time comes. A source
Of course, there are a number of elements included in the Inbox folder on three platforms: code for managing network communications, caching of objects, local persistent storage, managing user changes both locally and remotely, and supporting it while offline. This logic must be faithfully and correctly implemented by all three clients. Rewriting it three times into three different languages ββwill absorb significant engineering resources and slow down how quickly we make improvements for Inbox.
For iOS, we developed the open source cross-compiler J2ObjC to translate our Java data model to Objective-C, and again we get a natural API on which you can create your own Inbox Inbox application (complete with - [Reminder snooze]), Insightful the reader may wonder how we deal with impedance mismatch when translating from a garbage collected language (Java) to a counted link (Objective-C). As a rule, J2ObjC relies on autorelease Objective-C pools, so objects that are usually garbage collected are freed when the pool merges. One of the problems with this approach is the reference cycles; Where loops exist in our Java data model, we use the Java annotation to identify @WeakReference. When forwarding, the corresponding property in Objective-C will have the __weak modifier, thereby breaking the save cycle. In practice, we have found that this is a relatively small problem, and we have automation tests that indicate rare cases of new cycles crawling around the object model. A source
Communication between your main modules can be done using Dagger2 , which runs on Android / iOS / GWT. There is also a cross-platform JSON library called realtime-json . HTTP transport can be implemented in the kernel, at least for Android and iOS. Form GWT / JavaScript, you must do this on the client side.
Here are some sample applications to help you: