How Google Inbox shares 70% of its code across Android, iOS, and the Web
arstechnica.com
arstechnica.com
I wonder if the Google folks ever looked into RoboVM as a replacement for j2objc. It's a full AOT compiler, sharing the class library with Android with access to all iOS APIs (think Xamarin for Java/JVM languages). I tested j2objc when itmwas published as a potential way to get our libGDX stuff working on iOS, but it was extremely limited in its capabilities. Kinda reminded me of Oracle's terrible ADF.
[1] http://github.com/libgdx/libgdx [2] http://www.robovm.com
RoboVM gives you full access to all iOS native APIs in idiomatic Java. Have a look at the Javadocs [1] to get a feel for how that looks like. Currently not wired up to the Apple docs, but that's on our roadmap. We have quite a few ports of official Apple demo apps [2], a simple hello world looks like this [3].
You can even extend ObjC classes as if they were Java classes and/or implement Protocols. Binding of native APIs (C, ObjC) is accomplished via something called Bro, which is annotation-based and a lot simpler and faster than using JNI.
So, yes, i think RoboVM is a good fit for Rich-UI mobile apps. Performance is great (we use LLVM), and the bindings are pretty complete. We currently lack interface builder integration, but that's on the short term road map (and for anything other than a quick prototype you don't use IB anyways).
[1] http://docs.robovm.com/api/1.0.0-SNAPSHOT/
[2] https://github.com/robovm/robovm-samples
[3] https://github.com/robovm/robovm-samples/blob/master/HelloWo...
[4] https://github.com/robovm/robovm-samples/blob/master/HelloWo...
I especially like the web browser support, it feels good to step entirely around the browser.
[0] http://opensciencemap.org/map/#&scale=16&rot=-18&tilt=46&lat...
RoboVM is a very cool project. We ended up on Xamarin for the cross-platform project we were working on here internally, but, had RoboVM been a little more mature when we were evaluating cross-platform projects (this was around April of last year), it would've most likely been our first choice instead (we have a lot more in-house Java expertise than C#).
Generally the SQLite approach feels quite lowest common denominator, mainly because on Android the SQLite wrapper is so clunky. Get over that and you're into raw files territory, which has made me consider things like building LevelDB for bundling in.
Any wellfunctioning code that I have written I pack into my content generator and give access to via the YAML. The whole thing has gotten really ugly and desperately needs refactoring (it's in Perl and I am rewriting it in Stringtemplate) but it does help me with:
- the changes in the model that cascade down the frontends
- fixing a bug in one application that needs fixing in several others
- the fact that multi-platform model really is stressful since the brain needs to switch rapidly between different languages and platform APIs and this allows me to write code once and perpetuate data model changes on to all platforms.
So I think, take code of yours that works and wrap a codegenerator around it. It's better than using a framework where you don't know what's underneath. All the code is something you know and built.
There was a presentation at GWTCreate where Ray Cromwell laid out some of the magic on how they used GWT to handle this. The slides for the talk are here[0]. One of the key pieces here is that coding in Java gets you the web (with GWT), Android, and iOS using j2objc[1]. They posted a demo app showing this off[2].
The videos aren't up for the talks yet, but the Keynote from GWTCreate is posted (Ray gave that talk as well)[3].
[1] https://github.com/google/j2objc
All the helper functions felt like the ODBC abstractions that used to be all the rage, where you ended up typing 400x more code to abstract it than just writing some SQL.
Go straight for a ContentProvider, even if you are not sharing access to the data in SQLite. That makes it easier to build an observer pattern in Android. You can then build a SyncAdapter on the "back side" of this ContentProvider. Et voila, a synch'ed app.
It requires experience, vision and talent. It's perceived as very difficult because it's basically the same approach as academic research, but instead of being applied to general problems, it's a general approach for a set of very specific technical constraints.
Oh, and most people screw it up badly on most occasions.
Also a team of solid engineers.
1. Translate Java to ObjectiveC: generate an abstract syntax tree, transform the syntax tree, generate ObjectiveC.
2. Provide compatible APIs.
Don't get me wrong it's a lot of work, but shouldn't be more difficult than writing a compiler in general.
In all cases, though, the devil was certainly in the details! APIs, in particular, can surprise and harass the developers.
FTFY
The real blocking issue is very bad rendering performance, but that has been worked on for months now and you should see the results soonish. That's harder to illustrate in an HN thread. I've still got scars from the last discussion on this, so I'd advise people go read those old HN threads for insight. :)
Javascript is in a very good state these days in terms of cross browser compatibility, and while CSS support has converged between browsers in terms of correctness, CSS support has not converged on performance between browsers. Safari, Chrome Firefox, and IE have wildly different animation performance hazards on the same markup and debugging this often isn't trivial, for example, finding out that the GPU is stalling on texture uploads deep inside of the render loop.
One bright point, is that apps like Inbox are forcing these issues to the front, as is libraries like Polymer/Material Design. As the issues are raised and fixed, jank free rendering on mobile web platforms improves, hopefully reducing the need for native apps.
If I worked on Inbox, I wouldn't feel comfortable releasing anything like that on Firefox either, even if it was gated with a disclaimer. It wouldn't reflect well on Google or Mozilla.
Edit: using https://addons.mozilla.org/en-US/firefox/addon/enable-google... which works much better
The article seems to suggest that GWT is being (should be?) used for logic only. If the Web UI is sluggish, it probably isn't GWT's fault (disclaimer: I'm not a Googler & I have never looked at the Inbox code)
In case you are starting now with a new app then i think the best bet would be to use React native where you would get to reuse 100%[1] code across the platforms.
Google wrote separate UI code for each platform but react native does that conversion also by itself and leaves you with even lesser work\code
[1] - as claimed by react team
Plus, the React people stress that you should use custom UI on each platform. The key is that you get to build the UI using the techniques that work so well for the web.
I always worry about transpilers like this, though, because when there are issues, you get to debug in three places (original code, derived code, and translation code).
Any opinions from anyone else who tried using it?
I checked StackOverflow and there's only 21 questions with the tag (http://stackoverflow.com/questions/tagged/j2objc) so that put in the nail in the coffin for me. As an aside, that's how I make most of my decisions between frameworks and libraries, I just pick the one the highest amount of SO tags!
I've stuck to using GWT generated JS in a hidden webview on iOS, rather than J2ObjC.
I've found the process of compiling code on J2ObjC to be difficult and laborious. It may have improved but on initial investigation I ended up hacking a script to try and generate the correct command line for my project. Not to mention downloading and unpacking each library jar by hand.
GWT on the other hand integrates easily with Maven, pulls in all your dependencies and filters out unused methods.
Additionally, the code can be run anywhere else JS is available, in our case Windows Phone and Xbox One.
GWT was also an idea whose time had not yet come. I'm sure that the success of InBox makes the developers forget some of the blood, sweat and tears it probably took to toolsmith a cross-platform architecture. But they took a conservative approach, sticking to networking, sync, and local persistence. They picked parts of the app that would be using similar-enough APIs on all platforms that the abstractions don't get out of hand, and the learning curve for maintainers isn't too steep.
If I was looking at a big-enough project to justify the toolsmithing, I would be looking at how they did this.
I'm sure it's a painful process, and it might slow down development for a while. But, the ability to push changes across the incredibly fractured mobile/web/native front end landscape seems like an incredible advantage.
Another big language at Google is C++, which also has a cool cross-platform client story. Emscripten for web, Android NDK, iOS can use C++ libraries directly.
I do get the security part, I also like how both Android and Windows Phone 7/8 share architecture ideas with IBM i.
However, it would be nice to also expose the framework to the NDK without forcing everyone to write their own bindings.
Or at very least, expose other Android internal C++ libraries like SKIA, as part of the public NDK APIs.
Zuck also mentioned about facebook working on cross-platform platorm in last year's f8 conf.
where is this perception that proper cross platform development is an unsolved problem coming from? well written software has a platform layer which is usually small unless your product is trivial.
you also don't have to pay through the teeth with towering technology stacks.
maybe its connected to the fear of low level programming, or the fact that Google seem to not like using the established cross platform technologies, and made some pretty questionable decisions about the android development platform - like not giving a C/C++ compiler through the NDK for a long time despite the fact that everything they did was built on a foundation made with one so they obviously had it.
maybe they need a lot of platform specific code, but tbh i find that 70% a very unimpressive number. i would not even be impressed by 95%, i'd just call that 'normal'.
maybe this makes more sense of you are constrained to rapid application development, but given my experience with that a lot of the rational there is fallacious... i don't think i could build a cross platform app in a week without dropping down to C++/ObjC/Java and minimising the amount of Obj-C and Java as far as possible.
i suppose an important argument is that targetting the web with server side native stuff rather than client side java scripting things is a bit of a nightmare and lots of people don't even realise its an option...