[UPDATE: Since Mobile SDK 1.3 is released, I no longer recommend this. The launching of the emulator succeeds just fine under 1.3. Also, the major disadvantage of my suggested approach here was that since you would be launching the emulator outside of the Titanium Developer program, your Titanium.API.info() calls would not show messages inside the Developer console. So I’ll leave this post here for posterity, but I do not recommend it any longer.]
The slowness of the first-launch of the Android emulator can cause so much grief for Titanium developers targeting the Android platform. If the emulator loads slowly, the build of your own project often finishes before the emulator is ready, causing the emulator to just sit there when it’s finally finished loading. No error message is displayed to you to describe why nothing is happening.
Also, it’s my belief that the recent speed-ups to the code-build-release-code-build-release round-tripping under Android have actually made things worse if the first attempt to install the application on the emulator fails. It seems to me that subsequent attempts will then fail again, because Titanium doesn’t think that anything has changed since the last build/release, so the files in your Resources folder actually never make it on to the device’s SD card, which is used for the speed-up process. I’ve spent loads and loads of time trying to overcome this problem. It is extremely frustrating and I think that — with the way it is now — it can put some would-be Android developers right off of Titanium.
I’m glad to say that Appcelerator is aware of the problem and there are already some relevant tickets. But it’s not clear when any fixes will be pushed out to users.
So in the meantime, take my advice and save yourself the grief of the problems that can occur when the Android emulator (plus its virtual SD Card) is not ready to accept files from the Titanium installation process. Load the emulator before doing any development work in Titanium. To find out which command-line to use for the emulator, take these steps:
- Open Titanium Developer as per ususal.
- Create a dummy mobile project that you don’t really need.
- Go to the Test & Package tab for that project, and select the Android SDK plus screen size you want to target.
- Click Launch.
- Set the Filter to “Trace” and copy all of the contents of the console window. It doesn’t matter that your project is still building — we just need some lines up at the top of the trace.
- Paste your copied lines into some text editor, just so you can look through them.
Near the top of the trace, you will find the command-line used to start the emulator. Example:
[DEBUG] From: C:android-sdktoolsemulator.exe
[DEBUG] SDCard: C:Documents and Settingsbill.titaniumandroid.sdcard
[DEBUG] AVD ID: 11
[DEBUG] AVD Skin: HVGA
[DEBUG] SDK: C:android-sdk
[DEBUG] C:android-sdktoolsemulator.exe -avd titanium_11_HVGA -port
5560 -sdcard C:Documents and Settingsbill.titaniumandroid.sdcard
-logcat '*:d *' -no-boot-anim
(I put some line-breaks in there for clarity.)
Copy that command-line and paste it into a new editor (Notepad, whatever) window, then save it as a batch file or shell script, depending on your platform.
You may need to clean it up a bit. My example above, for instance, will not execute because of the space in “Documents and Settings”, so I needed to surround the whole “C:Documents And Settings….” path in double quotes. Also, I had to change those single quotes around “*:d *” to double quotes.
Now run that batch file / shell script when you’re ready to start your Android development for the day. And keep the emulator open!
When you do that, you’ll see magic like in my sample video here below (no sound.) Because the round-trip speedups done by Marshall Culpepper (@marshall_law) are friggin’ awesome when they work! Watch the video to see how fast it re-launches when I change app.js! Still not lightning fast, but much, much faster than before (thanks Marshall!I)