

Ask HN: Best way to write an app for both Android and iOS? - MasterScrat

I need to write an application that can run on both Android and Apple devices. At this point I have found a couple of solutions:<p>* Use a framework such as Appcelerator Titanium or PhoneGap,<p>* Use C++, and then write the UI parts both in Java and Objective-C (as C++ can be run on both platform),<p>* Write everything twice...<p>What are your experiences and suggestions regarding this problem?<p>EDIT: I'm working on the mobile application for our school, we need more than a website because we want to do stuff like Wifi triangulation, maybe also AR.
======
kwhinnery
(Disclosure: I work for Appcelerator)

I think you should take a look at Titanium from Appcelerator
(<http://www.appcelerator.com>). For data-driven applications or native apps
that don't require advanced 3D animations, it does a very good job providing a
native user experience and access to device APIs. To describe how it works
briefly, you write JavaScript code which maps to native APIs - that code is
then included in a native app binary along with a JavaScript interpreter, and
is interpreted at runtime on the device. A better/longer explanation is here:

[http://stackoverflow.com/questions/4217551/what-happens-
to-j...](http://stackoverflow.com/questions/4217551/what-happens-to-
javascript-code-after-app-is-compiled-using-titanium-mobile/4798547#4798547)

Titanium has been deployed in over 12,000 apps in the Android Market/App
Store, more than any other cross-platform framework (that we know of), so many
developers have found success using it. That said, no technology is a silver
bullet, so you'll need to take a look at your application and decide what is
the right move for you.

If at some point while using Titanium, you discover you need more native
functionality than we currently expose, it's easy to write a native extension
(well, easy if you know Objective C and Java). Guides are located at:

<http://guides.appcelerator.com/en/module_ios.html>

<http://guides.appcelerator.com/en/module_android.html>

Despite the success we see every day by devs using the platform, Titanium can
be a bit flaky at times - and I'm sorry to hear some folks have run into
problems with their specific use cases. Feel free to reach out to me directly
(community@appcelerator.com goes to my inbox) and I'd be happy to help out.

EDIT: We actually just demoed an AR app using the device camera, but the
source isn't up yet (not sure why not, but it will be open source). If you
follow our dev blog (developer.appcelerator.com) or keep up with our GitHub
account (github.com/appcelerator), the source will pop up there.

------
pistoriusp
Nothing beats native.

I've tried Appcelerator and you'll get to a point near the end where you've
got to do the other 80% of your application and the third party framework is
going to fight you till completion, or some state of completion that you're ok
with.

One of the problems is that the simplification also requires you to give up
your power.

If you're doing a simple application then maybe a third party tool will help
you, but in my experience I would rather work slowly and remain sane.

I would consider Appcelerator again if I needed to prototype something very
quickly.

~~~
rufugee
One of the nice things about Appcelerator, as opposed to Corona, is that it's
open source and they have guides (iOS:
<http://guides.appcelerator.com/en/module_ios.html>, Android:
[http://developer.appcelerator.com/guides/en/module_android.h...](http://developer.appcelerator.com/guides/en/module_android.html))
for extending the framework with native code. So, when you hit that inevitable
wall, you can drop to native code and make it work on both platforms. I find
the speed of development in Appcelerator quickly outweighs the drawbacks.

That said, if you're developing a game, Corona is the better option. It's far
more efficient in terms of FPS.

------
pbreynolds
If you want the best user (and developer) experience, write 2 different
codebases and share graphical assets.

Even though you could write portable C++, the API for getting to the hardware
is going to be pretty different. I have worked on a project where we developed
an app with identical look and feel on both Android and iOS simultaneously.
The UI was basically completely custom (designed in Photoshop by a 3rd party).

My biggest advice is to do the Android UI layout IN CODE. The iOS version was
completed in about 70% of the time of the Android project mostly because of
the slowness of developing the UI with XML/Eclipse and Android's immature
layout API.

~~~
temptemptemp13
UI layout in code can be a pain because you can't see what you're doing until
you do the compile-install-run which can be 30 seconds. That's a hefty amount
of time if you're just tweaking one visual element and need to run through
1-10 possibilities.

~~~
pbreynolds
Normally I would agree- ALL my iOS apps are done in Interface Builder. But if
you add more than 50 PNGs to an Android/Eclipse project, the iteration cycle
is well over a minute long compared to a 5 second recompile. That's not
counting the slowness of the Android emulator (hardware was faster for
debugging for me)

------
semanticist
Depending on what you need your application to do, I would definitely go down
the web app + PhoneGap route.

It's extremely easy to develop and test the app in a webkit browser, and then
in the relevant phone simulators, and PhoneGap will very very easily wrap your
web app into a native application - it also provides extra JavaScript APIs to
access some hardware features, like the camera and geolocation and so on.

You can use any of the existing common mobile web app frameworks (I actually
wrote about my experiences with several of them just last weekend:
[http://semantici.st/archives/223:ios-webapp-frameworks-
round...](http://semantici.st/archives/223:ios-webapp-frameworks-roundup)), or
do something entirely custom. You can certainly get a 'native enough' UI
experience on iOS - I've not tried Android yet.

However, if you're planning to do anything that's really performance-limited
this approach won't work. The performance is exactly as you'd get in a normal
mobile web app, and if you're expecting to do, say, gaming or perhaps
something complicated using the camera (like 'Layar' or 'Word Lens' type AR),
you'll need to be writing native code.

~~~
matty
To get an idea how terrible PhoneGap can work in practice, check out the
O'Reilly iPad app. The performance just isn't there for some applications.

~~~
semanticist
Remember that PhoneGap really isn't anything more than a thin wrapper around a
web app. Performance/usability is going to be heavily influenced by how you
write that web app.

I'd be more interested to know what web framework O'Reilly used that was slow,
rather than it being PhoneGap per se.

~~~
matty
They used PhoneGap, in fact it was Nitobi that created the app.

[http://blog.safaribooksonline.com/2010/10/18/an-update-on-
ou...](http://blog.safaribooksonline.com/2010/10/18/an-update-on-our-ipad-app-
safari-to-go/)

~~~
semanticist
Have you personally used PhoneGap? It sounds like you don't quite understand
how it works.

For an iOS PhoneGap project, inside the Xcode project there is a 'www'
directory into which you stuff your HTML, JavaScript, and CSS files from your
mobile web app. PhoneGap then creates a webview and loads your index.html in
it.

PhoneGap by itself cannot be used to make any kind of an application. You also
need a web app that works outside of PhoneGap (barring some PhoneGap-specific
JavaScript APIs which you can optionally include to get access to device-
specific information and features), and that web app presumably would either
use one of the common frameworks or be written from scratch.

Hence my point that what's more interesting to know is what web app framework
they used, since that'll have a bigger impact on performance and especially
usability than just "it's PhoneGap".

------
fookyong
Depends on what kind of app I suppose, but if it is anything to do with 2D
gaming, I'm totally _loving_ Corona so far.

I come from a web background (php/javascript) and I'm lost on Objective-C. But
I picked up the basics of Lua in about a day and the next day had built a
simple game. It's wickedly fast to get to grips with and the documentation is
detailed and easy to read.

<http://www.anscamobile.com/corona/>

~~~
ConceptDog
Voted up for Corona. For 3D Games, look to Unity. I know people are have allot
of success developing cross platform using it. But for 2D on mobile, Corona
wins.

If they ever decided to go the Appcelerator work and come up with a deployment
that also targets OSX and Windows at the same time, they'd absolutely rule.

~~~
kwhinnery
I agree, we need to support unified projects.

------
headhuntermdk
Write everything twice.. Two separate codebases.. It's gonna suck but will at
least give you the opportunity to deliver the best experience that your users
expect from each platform

------
eapen
Adobe AIR/Flex has the option to export files to iOS, Android and Blackberry.
I tried exporting a demo app to Android and it worked well. I havent tried the
other platforms though. Obviously, I doubt the performance would be as good as
a native app but a mobile application for a school which doesn't require a
game engine, I would say Adobe AIR/Flex is the way to go. But since you
require Wifi triangulation or GPS, this might not be an option.

~~~
cpeterso
> I would say Adobe AIR/Flex is the way to go. But since you require Wifi
> triangulation or GPS, this might not be an option.

Adobe AIR supports geolocation (using GPS and/or Wi-Fi) for both Android and
iOS devices:

[http://www.adobe.com/devnet/air/quick_start_as/quickstarts/q...](http://www.adobe.com/devnet/air/quick_start_as/quickstarts/qs_as_geolocation_api.html)

------
clojurerocks
Ive been going through the same issue and unfortunately there isnt a clear cut
answer. Initially i was looking at phonegap, titanium and rhomobile. The
problem with them is each has pros and cons and its very confusing to really
understand what they are. Theres also fanboys of each which makes it even more
difficult to understand what separates each.

You can also go the jquery mobile/sencha touch/mobile rails route which is the
direction i am going somewhat myself. These are actually pretty nice and
fairly powerful for a basic application. Although jqeury mobile is newly
developed as is mobile rails whereas sencha touch is pretty mature. Theres
also jquery touch but i dont really know that much about it.

The question really comes down to what is the application doing. If you are
doing a game you have to go native unless you can do something with html5
canvas. Also if you need to use something like gps or the camera or the
accelarator you have to go either native or use phonegap, appcelarator or
rhomobile as html5 through just a mobile browser cant give you access to the
hardware.

What ive been ending up doing is just using straight jquery because im
familiar with it and then seeing where my apps need to go.

~~~
clojurerocks
Just to add that you cant write write native ui code in android with c++. The
NDK is used for games and 3d applications or to access libraries that are
coded in c++ already.

Another question is will you also have to make your app availalable to
blackberry or other devices such as an ipad. If so then phonegap rhomobile
appcelarator and sencha touch, jqeury mobile yada yada yada might work best
because theyre focus really is one having one codebase be able to be used on
multiple platforms.

If you only have to target the iphone and android and you have a mac and want
to learn how to code each then just go native. Ive played around with android
myself so i understand why that would be needed as opposed to using html5. But
if you havent done that then it wont make sense.

Oh good luck to you in your endeavor. Building mobile apps are fun but a pain
in the ass right now because of all the fragmentation.

------
androidjim
Depends on what kind of app it is.

Is it a video game (use C++) or a web app (use PhoneGap), or a normal app
(write everything twice, 'cause users expect platform specific look-and-feel.)

For what it's worth, two additional cross-platform frameworks you might want
to look at are:

Corona (Lua-based, already used for hit iOS games.)

Unity3D (cross-platform 3D game engine.)

------
xpaulbettsx
It is more expensive because you'd have to license both, but you can also use
MonoTouch and MonoDroid, and your core libraries (i.e. the .NET Framework)
would be the same

------
deweller
You can check out Corona from Ansca as well: <http://www.anscamobile.com/>

This IDE is geared for graphical oriented apps (games).

~~~
MasterScrat
Corona looks good (even if we're not doing a game) but as students a free
solution would be better.

~~~
chopsueyar
<http://www.anscamobile.com/education/>

How about $49.

------
sashthebash
Shameless but on-topic plug: If you have content that needs to be displayed
within both apps you could check out the flexible CMS my startup just created
for mobile applications: <http://storageroomapp.com>.

We are currently testing the system, let me know if I should invite you to the
beta.

------
willmacdonald
I would say use Appcelerator. It generates native apps for iOS and Android, so
runs fast and can access all the hardware features, or at least more so than
Phonegap can. I'm pretty certain Appcelerator can export to iOS, Android,
WebOS, Windows7 and Blackberry (for a fee).

------
adziki
I'm in the middle of trying to solve this challenge at work as well. I've
bounced back and forth between a PhoneGap like solution, and doing it all in
HTML with a web view wrapper.

The benefits of the HTML with webview are consistency, developing once, and
being able to have a web app, blackberry app, webOS app as well.

However, if the app you're making needs to really leverage the functionality
of the device, PhoneGap or making the device-specific logic in that native
language is probably worth the extra effort (the trade off there is in
efficiency of your app, and may be limited by the functionality of web pages
on your mobile platforms.)

------
palguay
I created a website for toddlers in HTML5 +JS <http://microangels.in> . The
website works great in safari, firefox & chrome but when I tried to use
phonegap the page would not show up. Debugging in phonegap is a pain and I did
not find much help in documentation, mailing list or IRC . I ended up using
the android webview + Jquery mobile and the app works great I will need to
look at the iOS next. So I would say that go with html5 and the native webview
and it should be easy to add in the parts that need to be written in Obj-c or
java easily instead of trying to figure out the frameworks

------
SeamusBrady
How about Runtime Revolutions LiveCode? I have been a fan for years - never
used the mobile version but they are a great little company and their other
products rock.

LiveCode is an offshoot of the HyperCard codebase and will run on everything
from a toaster to your car. The apps seem pretty slick in the demos. Android
support in in testing.

<http://www.runrev.com/products/mobile-deployment/overview/>

------
pdebruic
Write it in Smalltalk. Squeak runs on both platforms.

------
alexobenauer
If you had to have the same code base for both, I would say use Sencha Touch
and make native apps with just a web view in it for each.

Sencha touch: <http://www.sencha.com/products/touch/>

In my experience, I've found Sencha touch to be an incredible framework for
developing native looking apps.

------
loudmax
Is there a particular reason why you can't or don't want to write it as a web
page instead?

~~~
mathrawka
And make a simple app that shows the application via a webview

~~~
semanticist
That's basically what PhoneGap does, although it also gives you JavaScript
APIs to get at hardware features like the camera.

------
tocomment
C++ on android? I hadn't heard of that.

~~~
harph
NDK <http://developer.android.com/sdk/ndk/index.html>

I'm playing with it at the moment. It might seem a bit frustrating first, with
all those JNI naming conventions and getting it to integrate with Eclipse, but
hopefully it's performance will make up for it.

------
robwgibbons
HTML + JavaScript + PhoneGap is a viable solution.

------
cnkt
Use HTML+CSS+JS+PHP. Done.

~~~
mohsen
come at me again bro

