-
Notifications
You must be signed in to change notification settings - Fork 0
Installing the Android SDK
If you haven't already you should follow the steps outlined in Installing Apache Cordova as this guide assumes you have already got node.js, npm and the cordova command line tools installed. If not, then go there and do that, then come back here.
$ brew install android-sdk
I haven't done this, but probably when the installation finishes it will output where it has installed the sdk (probably something like /usr/local/Cellar/android-sdk/
).
The Android SDK is available for download from here: http://developer.android.com/sdk/index.html
The headline item on that page is the Android Studio, which is an IDE like XCode. We might use this at some point, but for now if you ignore it and just look for the link to download the standalone SDK tools: http://developer.android.com/sdk/index.html#Other
Look for the OSX .zip file, and click to download it (it's a big file so will take a while).
Once it's downloaded, you can double click it to unpack it, then should place the extracted directory somewhere sensible in your home directory. I put mine in /Users/sam/Workspace/android-sdk-macosx
, but put it wherever makes sense. Make a (mental) note of wherever you extracted it as you'll need this for the next step.
For the Cordova command line tools to work for Android, they need to be able to find the various executable tools included with the SDK, so to do this you need to add the SDKs directory to your shell's [[$PATH
variable]].
Note, throughout this text I'll be referring to either the 'shell' or your 'terminal', and by this I mean open the Terminal app on your Mac; actually by preference I'd recommend installing iTerm2 - it's not amazingly more powerful or anything, but it is better.
To do this, in a text editor of your choice, open or create the file called: .bash_profile
in your home directory. If you are trying to find this file via the Finder, you probably won't see it because the fact it starts with a .
means that Finder treats it as a hidden file by default. I don't know how to get Finder to show hidden files, but if you open a terminal window, and type the following 2 lines, you should be able to see whether or not it exists:
cd $HOME
ls -a .bash_profile
Once you have the file open in an editor, then add the following line to the end:
export ANDROID_HOME=${HOME}/Workspace/android-sdk-macosx
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools
Make sure that value entered for ANDROID_HOME
matches the location you extracted the SDK earlier.
If you now open a new terminal window, you should be able to verify that your updated $PATH
variable has been loaded successfully by doing:
echo $PATH
If this hasn't worked, stop here and bug Sam about what's gone wrong.
Before you can use the SDK, you need to install some Android platforms. These are required both to run the emulator and to build the app to install on a device.
To do this, from within your open terminal window type:
android sdk
This should launch the Android SDK Manager, which looks something like this:
From this you need to select some platforms to install. Don't click everything, because they are huge, and will fill up your hard drive. The ones I have selected are:
- Tools > Android SDK Tools (latest)
- Tools > Android SDK Platform-tools (latest)
- Tools > Android SDK Build-tools (latest)
- Android 5.1.1 > Documentation for Android SDK
- Android 5.1.1 > SDK Platform
- Android 5.1.1 > ARM EABI v7a System Image
- Android 5.1.1 > Google APIs
- Android 5.1.1 > Google APIs ARM EABI v7a System Image
- Android 4.4.2 (API 19): everything
which should be enough for a Lollipop device. Ultimately we should probably also build for older devices, but don't worry about that now.
Once you've done all that you can go ahead and click the Install x packages...
button. You'll have to click through some licence agreement screens, but once you're done with that, be warned it will probably take a while to download as the system images used for the emulator are big.
Once all the packages are installed you should be able to try building an android version of the default Cordova app like this:
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add android
cordova build
and try booting the emulator like this:
cordova run android
if the emulator doesn't load or throws an error you might need to edit or recreate in which case do the following:
android
up will pop the same Android gui from before, and under tools select 'manage AVDs' and either create or edit the emulator as necessary.
If you get the following error:
INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
then it's because you already have the app installed and the certificate is borking, so just delete the app on your phone. more here: http://stackoverflow.com/questions/3185444/how-to-deal-with-install-parse-failed-inconsistent-certificates-without-uninstal
adb logcat CordovaLog:D *:S