Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Best way to write an app for both Android and iOS?
78 points by MasterScrat on Feb 10, 2011 | hide | past | favorite | 50 comments
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:

* Use a framework such as Appcelerator Titanium or PhoneGap,

* Use C++, and then write the UI parts both in Java and Objective-C (as C++ can be run on both platform),

* Write everything twice...

What are your experiences and suggestions regarding this problem?

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.




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.


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...) 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.


Had the same experience with Appcelerator. Not knowing Objective-C it was a lot easier to get ideas into code quickly for prototyping, but when I ended up having to read all of their source and writing custom modules to get what I wanted done I decided it was not worth it. (Side benefit: this is how I got comfortable w/ Objective-C)

If your app is brochureware or a simple web app port to mobile it probably works well. If you are pushing anywhere on the edges it starts to get difficult.

Organize your application really well and it will be easy to port between the two platforms for any models/libraries you write where the concepts are the same.


I'm also going the native route and have briefly experimented with PhoneGap, Sencha, Appcelerator.

I recommend you analyze what features you're trying to leverage: camera, GPS, OpenGL ES/Rendering. Also, try and see what code you can reuse to be consistent across both platforms: the AR feature, wi-fi triangulation, and UI (UX will inherently have differences between iOS/Android).

My experiences with the camera include low-level image processing algorithms that 3rd party applications can't really optimize for. This is something from my own codebase that's fairly independent from everything else.

GPS/wi-fi triangulation is tricky because it's more understanding how iOS and Android track your location and maintain state. Whether or not you use a 3rd party application or your own code to parse it is up to you. As with a lot of things, the more you understand, the better decisions you can make ;).

Finally, UI (because I haven't done a lot of Open GL/rendering)... it's a pain to work with across different platforms, so leverage whatever you can to simplify this process. If all you're using 3rd party applications for is to translate iPhone UI to Android UI, go for it.


Agreed,

PhoneGap + jqtouch (or perhaps jquery mobile as it matures) is an awesome way to get going fast but that last mile can be torture, especially if you're working with an uncompromising customer/designer/etc.

At some point someone is going to throw on the brakes because "x doesn't y like an iPhone app" and then it gets ugly.

I think that you can do some very cool stuff using the "web app in a can" approach and I think it's appropriate for a lot of the typical "corporate"-type apps as long as you can manage expectations and stress the cross-platform angle (which can be almost zero-effort, check out https://build.phonegap.com/faq).

But pistoriusp is right, if you're breaking new ground then time invested in learning the native way is well spent.


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.


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.


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)


(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...

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.


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...), 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.


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.


Not just the performance. A lot of the UI behavior was just wrong. Scrolling in particular was a disaster. Maybe they were using PhoneGap badly, but still--in a native iOS app it's quite easy to get scrolling to work right, and apparently in PhoneGap it's not.


no idea why you would get downvoted for this, it is clearly just a well stated opinion without flame etc.

However, PhoneGap shouldn't be completely to blame for any one applications performance. If many PhoneGap applications performed poorly, then you could make the case. PhoneGap apps should perform as well as any web-based app on the same device. It is up to the developer to make efficient use of javascript animations, etc. in order to provide the best user experience.


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.


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

http://blog.safaribooksonline.com/2010/10/18/an-update-on-ou...


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".


How is performance in the browser for PhoneGap applications? I'm not expecting anything native, but I tested some of the sample apps on my Android phone and they were... /underwhelming/ - clicking anything would take around 3 seconds just to switch to a new view, etc.


My experience - at the moment - is specifically with jQTouch and iPhones. I've found that it performs well for simple views, but haven't tried anything complex.

In general, PhoneGap's going to perform the same as if you tried it in the phone's browser. From some stuff I tried before, Android browser performance was noticeably slower than iPhone browser performance, but not so much as to make it unusable.

I suspect it'll depend heavily on the device you're testing.


I totally agree with this approach. It's what we use, and it's really quick to get started with.


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/


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.


I agree, we need to support unified projects.


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


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.


> 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...


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.


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.


Actually, as mentioned here already, you don't have to go native if you're writing a game. You can use Corona with great success, or Unity3D if you're going the 3D route.


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


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.)


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

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


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



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.


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).


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


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.)


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/


Write it in Smalltalk. Squeak runs on both platforms.


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.


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


The performance and feel of Google maps inside a WebView is terrible compared to the native maps applications. I recently attempted this and was incredibly disappointed. Decided eventually after fighting with Titanium before trying Phonegap to just do native versions.


We need to have access to the hardware. One of our features will be positioning using an advanced Wifi triangulation system.


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


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


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


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.


HTML + JavaScript + PhoneGap is a viable solution.


Use HTML+CSS+JS+PHP. Done.


come at me again bro




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: