I plan to create an application on iOS, Android and a website with AngularJS.
But for not having to rewrite the business code on each app, I would like to reuse as much code as possible.
To be able to execute the core of the project on any platform, I have to use a web language.
Through different articles, I plan a common architecture to separate the business logic of the project - core - with the UI which will reimplemented for each system (UIKit for iOS, AngularJS and Polymer for the webapp, etc.)
The goal of this architecture is to respect important software engineering principles such as information hiding by decomposing requirements in modules, DRY and SOLID
Here for iOS (almost the same for Android):
The code of "core" will be executed through a virtual machine as this article shows us: http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript
Here for AngularJS:
Now that you know everything about the architecture, here are my questions.
I don't have enough experiences and feedback on the web-langages to be able to make a smart choice. After few researches, I found that there are various options:
Dart:
Javascript ES6: Event if it's not fully implemented in browsers yet, it's possible to start using ES6 with Traceur compiler.
Thank you for reading.
I know this wasn't one of the options you listed but don't automatically rule out C++. This is what Dropbox uses for example, they even open sourced their tools for this purpose:
C++ to Java/Objective-C API generator:
https://github.com/dropbox/djinni
Sample "native" app for Android/iOS:
https://github.com/libmx3/mx3
Interesting article on the subject with more links:
http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cross-platform-development/
Updated Answer:
If you really don't want to use C++ and are okay with the bloat you'll get from going non-native then you can try the following:
https://github.com/MobileChromeApps/mobile-chrome-apps
That project is Google's fork of Cordova and adds a bunch of new features and benefits.
There is a Dart wrapper over Chrome APIs here:
https://github.com/dart-gde/chrome.dart
Basically, you would write your app in Dart using plain HTML5 technologies, then for certain things you'd use the Chrome APIs (device state, etc). Then you can deploy:
This is an interesting topic. Here is what I learnt from the "GWT.Create" conference, the google guys showed how they did the cross platforms project:
First the DataStore and Model part in your picture should be done in an external server, so it's already crossed platforms.
UI render must be done in native way individually, that's the best solution.
They implemented the shared logic (complicated calculation, encryption, etc) with Java, for Android it works out of box, for Web they use GWT to translate Java to Javascript and for iOS they use J2ObjC, a new Google product. You can find it here:
https://github.com/google/j2objc
They also mentioned the C/Cpp solution, it's not a bad idea at all, Java is just a high level language and easy to use in most case.
If you want to create a cross platform application (iOS/Android/Web) the best thing you can do is sharing as much code as possible between these platforms. You could use something like PhoneGap/Cordova but this does not feel very native all the time. Event the best PhoneGap app feels not that native because it does not use the native UI. Instead in embeds a browser in a native UI container.
What I recommend is using a project structure as follows:
The the core project is shared between the ios, android and web project. You can write the core project in Java and use GWT to translate this code into JavaScript for the web project. For the android project there is nothing to do because Android uses Java. For your ios project you can use J2Objc to transpile you core Java code into Objective-C.
What come into the core project?
Use interfaces and abstract base classes as well as factories as much as you can.
conversations, reminders, and contacts It also deals with the difficult task of network management and offline synchronization, where the app is used offline, reminders are made, and e-mails are sent. It's up to the app to store all that and fire it off to the Internet when the time comes. Source
Of course, there are a number of elements of Inbox that are shared across the three platforms: code for managing network communication, caching objects, local persistent storage, managing user edits both locally and remotely, and supporting it all while offline. This logic must be faithfully and correctly implemented and kept up to date on all three clients. Rewriting it three times in three different languages would soak up substantial engineering resources and slow down how quickly we make improvements to Inbox.
For iOS we developed the now open source J2ObjC cross compiler to translate our Java data model to Objective-C, and again we get a natural API on which to build our native iOS Inbox app (complete with -[Reminder snooze]). The astute reader may wonder how we deal with the impedance mismatch when translating from a garbage collected language (Java) to a reference counted one (Objective-C). Generally, J2ObjC relies on Objective-C autorelease pools, so objects normally garbage-collected are instead freed when a pool drains. One problem with this approach is reference cycles; in places that cycles exist in our Java data model, we use a Java annotation to identify the @WeakReference. When transpiled, the corresponding property in Objective-C will have the __weak modifier, thus breaking the retain cycle. In practice we’ve found this to be a relatively minor problem and we have automation tests that flag the rare cases of new cycles creeping into the object model. Source
The communication between your core modules can be done with Dagger2 it runs on Android/iOS/GWT. There is also a cross platform JSON library called realtime-json. The HTTP transport can be implemented in the core at least for Android and iOS. Form GWT/JavaScript you have to do it on the client side.
Here are some sample apps that should help you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With