Peter_vdL

Porting apps from iOS to Android devices

by Peter_vdL Motorola 01-24-2011 02:24 PM - edited 01-24-2011 02:24 PM

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
In general, it takes the same effort to port an iPhone app to Android, as it did to write it originally.  But if your app is one of the unusual iOS apps written in ANSI C or C++, it can likely be ported to Android quickly and cheaply, by using the NDK.
Cheers,
Peter van der Linden

Comments
by Android Devices(anon) on 08-01-2011 01:36 AM

Well Peter you have done a great job i really appreaciate the way you explained the whole scenario of of android devices and iOS. EVen there are couple of things that i was completely unaware of.

by Peter_vdL Motorola on 08-03-2011 09:31 AM

Thanks for the feedback.

 

Peter

Post a Comment
Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
reCAPTCHA challenge image
Type the characters you see in the picture above.Type the words you hear.
About MOTODEV Blog
The MOTODEV blog keeps you updated on mobile app development news from MOTODEV and the Android developer community.

Subscribe to our RSS feed Subscribe via RSS

Follow Us:
Fan MOTODEV on Facebook Join the MOTODEV LinkedIn Group MOTODEV on YouTube

motodev profile

motodev @officemicro Thanks for joining us! 7 days ago · reply · retweet · favorite

motodev profile

motodev Do u have questions about the Google+ Hangout happening right now? Go to Google Moderator and ask a way: moto.ly/askl2cloud 7 days ago · reply · retweet · favorite

motodev profile

motodev Use Schema Builder to build out your data model. Find out more at our Google+ Hangout now: moto.ly/l2cloud #l2cloud 7 days ago · reply · retweet · favorite

Our Blog & Comment Policy
Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Motorola. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Motorola or any other party.

Remember, when you comment, please stay on topic and avoid spam, profanity, and anything else that violates our user guidelines. All comments require approval by Motorola and can be rejected for any reason.

For customer support issues with your Motorola phone go to the Motorola customer support website.