Skip to content

Instantly share code, notes, and snippets.

@danbri
Created February 22, 2012 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbri/1887346 to your computer and use it in GitHub Desktop.
Save danbri/1887346 to your computer and use it in GitHub Desktop.
==GETTING STARTED WITH ANDROID SDK, CORDOVA (PHONEGAP) DEVELOPMENT ON OSX.==
1. download sdk
TellyClub:Desktop danbri$ ls ~/working/android/android-sdk-macosx/
SDK Readme.txt add-ons docs extras platform-tools platforms samples system-images temp tools
TellyClub:Desktop danbri$ ls ~/working/android/
android-sdk-macosx android-sdk_r16-macosx.zip
2. put those tools/ and platform-tools/ on your path (e.g. in .bash_profile)
3. In the SDK dir, the readme guides you to do this:
tools/android update sdk --no-ui
...which will (in text console) grab a lot of actual Android distribution files. Wait until this is done.
Alternatively, the 'android' tool (from tools/, but which is now hopefully on your PATH), has a gui. Take a look at all the stuff it's installed.
4. You'll want PhoneGap, which is now called Apache Cordova (briefly 'Apache Callback').
There is a Git repo c/o Apache's incubator. Expect to see various names for the same stuff until things settle down.
https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=summary is an HTML overview.
The Git repo URL is https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git So
git clone https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git
Then in incubator-cordova-android/README.md instructions such as:
To create your cordova.jar, run in the framework directory:
android update project -p . -t android-15
ant jar
...so do that, ie. for me it was
TellyClub:incubator-cordova-android danbri$ cd framework/
TellyClub:framework danbri$ android update project -p . -t android-15
Updated project.properties
Updated local.properties
build.xml: Found version-tag: custom. File will not be updated.
Added file ./proguard.cfg
TellyClub:framework danbri$ ant jar
Buildfile: /Users/danbri/tmp/incubator-cordova-android/framework/build.xml
...[...] etc etc.
Then go back up .. above framework/
and make a test e.g.
TellyClub:incubator-cordova-android danbri$ bin/create HelloFoo
Pop into that dir with cd HelloFoo/ and try:
TellyClub:HelloFoo danbri$ ant debug install
This shoudl fail as you haven't configured any devices yet.
[exec] error: device not found
We need to teach the installation about some particular emulated android machine, so we can run the emulator with a command like this:
emulator -avd danko1
Our goal is for it to work, in which case we'll see something like this after trying 'ant debug install' in the HelloFoo/ dir:
install:
[echo] Installing /Users/danbri/tmp/incubator-cordova-android/HelloFoo/bin/cordovaExample-debug.apk onto default emulator or device...
[exec] 2515 KB/s (126303 bytes in 0.049s)
[exec] pkg: /data/local/tmp/cordovaExample-debug.apk
[exec] Success
So how to set up 'danko1'?
First we want to know the kinds of device we can choose from for our emulated Android. Do this:
android list targets
Which will spew out a lot of info along the lines of this entry:
id: 4 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
ABIs : armeabi
OK, so if we want an old 2.2 machine, we see that it's ID is '4', hence:
android create avd -n danko1 -t 4
Alternatively, you can use the 'android' GUI and do this under 'Manage SVD' settings area.
And now we run our emulator,
emulator -avd danko1
We can confirm it is known to be running too, try this:
TellyClub:HelloFoo danbri$ adb devices
List of devices attached
emulator-5554 device
Presumably real actual physical phones show up in much the same way, but that's another problem.
See http://stackoverflow.com/questions/4974568/how-do-i-launch-the-android-emulator-from-the-command-line for related reading here.
5. Er, so we have a device defined with 'android create avd namegoeshere' and running via 'emulator -avd namegoeshere'. This means we can now
return to our generated Android project directory that PhoneGap/Callback/Cordova built for us, and with 'ant debug install' install our app.
6. Edit assets/www/index.html and nearby to improve the app.
7. Be patient while the emulator starts up; it can take a minute or so.
8. Re-order the above steps after having read them all.
By the end of this you should be in a classic edit / test / screwup / retry Web developer cycle, albeit a bit slower than
you're used to with a browser.
To re-send the freshly rebuilt app to running emulator, this seems to work:
TellyClub:HelloFoo danbri$ ant clean debug install
see also http://www.netmagazine.com/tutorials/getting-started-phonegap
===APPENDIX===
Using a real phone (plugged into OSX USB port)
http://developer.android.com/guide/developing/device.html
ON YOUR PHONE
in Settings >Application > Development turn on USB debugging (and some oyther stuff, probably)
danbri: howto: https://gist.github.com/1746755
danbri: http://i.imgur.com/QDFLB.png
18:43 libby: yay ;-)
18:46 danbri: holy living fark
18:46 danbri: it worked!
18:46 danbri: in the device, you just go into settings >applications>development
18:46 danbri: and turn on USB debugging
18:47 danbri: then it shows up with 'adb devices' command, and the ant command installs to the physical phone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment