I am in the process of putting together a mobile development class and have been trying to figure out the best ways to get students who are new to PhoneGap and Mobile development going on cross-platform development. One of the issues I have been trying to solve is the fact that PhoneGap apps use a different phonegap.js file on each platform. This is a problem that I do not feel is well documented and one that is not easily and cleanly solved.
Since PhoneGap applications require these different JS files I have been unable to find a good way to start building a PhoneGap application in, for example, Eclipse with the Android Development Tool as an Android project and then be able to quickly and easily switch over to XCode and launch the same application as an iOS app. I always need to go and replace the phonegap.js file with the iOS one first and then switch it back before I go back to working in Android. Not a great workflow.
I could probably solve the problem with custom build scripts. I could set up build scripts for both iOS and Android to properly retrieve the correct file and stuff it into the build prior to compilation, but this is not something I want to take the time to do in the classroom (I also don't want the students to have to worry about trying to set up ANT at home). This also prevents me from having an application that can simply be downloaded from GitHub and run without modification. It's also more code to manage. I would need to maintain X number of build scripts (one for each platform) for all of my projects. Sounds like a PITA.
So I wanted a way to dynamically load the proper phonegap.js file depending on the platform. I am hoping there is a better way (or that a better one will come along), but in the meantime this (somewhat hackish) approach seems to get the job done and allows me to run and test my applications on multiple platforms without code modification or custom build scripts.
This approach sniffs the user agent of the device and determines if it is an Android device or an iOS device and then loads the appropriate phonegap.js from a subfolder. I see no reason why it would not work for additional devices (BlackBerry, Windows Phone 7, etc) support as well.
I admit I do not like this approach, and would love to see a better one. This problem does not seem to be discussed much out there. Maybe others are not having the issue for whatever reason, but while developing it was one of the first problems I came across. Maybe I am doing something wrong.
Thanks for your comments and ideas.