- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content
Porting apps from iOS to Android devices
A colleague recently asked me a timely and reasonable question, "How much effort does it take to port an app from iOS to Android?" It turns out that software portability has a precise definition. Quoting from Wikipedia, "Software is portable when the cost of porting it to a new platform is less than the cost of writing it from scratch. The lower the cost of porting software, relative to its implementation cost, the more portable it is said to be."
The more you can re-use, the less effort porting takes
How much of the source code making up an iOS app can be re-used on Android? Most iOS apps are written in Objective-C, while Android apps are written in Java and XML. Objective-C is not supported on Android. So you cannot directly re-use this kind of iOS coding. It's not a complete shut-out - some of the drawable resources (images and icons) can be reused. Android supports many more screen sizes and densities than iOS - so more drawables may be needed. And any SQLite database code can probably be reused. But these elements are usually minor compared to the app logic and coding.
Under most circumstances, porting to Android involves a complete rewrite of the Apple app. The effort that it took to write the iOS app, is about the same as the effort it will take to get it ported to (working on) Android. If the programmers who wrote the original code can do the port, then there will be a modest time-saving there.
What if the iOS app is written in ANSI C, C++?
There is one special circumstance, however. Porting is much simpler if you have an iOS app that is written in ANSI C or C++. Most iOS apps aren't written that way, but some are. The classic example is a game engine. Game engines are often written in ANSI C++, with maximum portability as a design goal. You can quickly bring up such an engine on iOS by creating a thin Objective C/iOS interface layer, and coding in ANSI C/C++ above that. Android has a NDK (Native Development Kit) allowing the deployment of ANSI C/C++ code, so you can use the same approach of a thin Java layer that interfaces to C/C++. Then there is very good code re-use on Android for C/C++ code from iOS!
How to use the Android NDK
The Android NDK is a companion download to the SDK. You download the NDK. Put it anywhere on your PC, and uncompress it. There's a shortcut for installing the NDK using MOTODEV Studio. To bring over the NDK in MOTODEV Studio, click on MOTODEV > Download Components ... Native Support. Then click OK, let the download complete, and restart MOTODEV Studio. While on the topic, let me mention there are some improvements planned for the NDK workflows in Eclipse. Motorola is working with the CDT project to define and create the improvements, with a shipping date later this year (2011).
Put your native code sources in <project>/JNI/...
in
your MOTODEV Studio workspace. Create a small makefile describing
your native code to the NDK. There's a command line script to
build your native code. Since your native code is kept in your
Eclipse project workspace, it's easy for Eclipse to link to it.
You can choose to call into C/C++ using the Java Native Interface, or by
setting up an android.app.NativeActivity class for which you provide
the surface, focus, and input handlers.
There is an excellent blog post on this topic by highly-talented programmer Phil Hassey. He describes his experience porting a large C++ app to Android.
It's an
instructional read for anyone interested in low-level coding details.
The approach of using the NDK for porting, rather than performance
improvements, did not escape attention at Google. The Android
team put a lot of effort into the NDK
specifically to empower this kind of development. The
results were
described in a recent blog post on the Android developers blog.
The Bottom Line