Friday 6 March 2015

Setting up the Android Platform

I'm going to preface this is a warning. A lot can, and likely will go wrong when you attempt to package your app for each platform. I'll be covering android again, and most of the work is done via installing the various SDK's and ensuring the PATH environment variable is correct. If you haven't already, download and install the latest JavaSDK, Android, and Apache Ant. Java and Ant should automatically update your system's environment variables, but in the event it fails; you will be doing it yourself. Android should as well but it failed to in my case. Chances are though, you will need to add an Environment Variable yourself. So heres how to do it:

Windows 8:

  1.  Go to your windows start screen 
  2.  Type system into the search box and open it 
  3.  Open the Advanced System Settings on the left side of the window 
  4.  The button to access the Environment Variables should be right above the Cancel button in this window 
  5. Your variables should be in the bottom half of the window, that's where the system wide variables are. 

Environment Variables in this case is sort of a shortcut that the operating system knows of. When you run ipconfig from the command prompt, your computer knows exactly where to find it, regardless of your current working directory (which is usually in your documents folder). In the case where you are trying to run non-windows programs in that manner, you need to tell it where the relevant folders are. That's exactly what were doing with Environment Variables, we are creating shortcuts for the Git bash to use. So if you try to run a command in Git bash, and get an error about ANDROID_HOME, you know your Environment Variable for the Android SDK is not correct, or missing.

There should System variables for ADT_HOME, ANDROID_HOME, ANT_HOME,GIT_HOME, and JAVA_HOME. Additionally, there should a few in the PATH variable. The PATH variable is a pain. The window it is housed in cannot be resized, and you have a massive string contained in a small text window. For example, here's what my PATH variable looks like:

C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\nodejs\;C:\apache-ant-1.9.3\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\Java\jdk1.8.0_25\bin;    %ADT_HOME%\tools;%ADT_HOME%\platform-tools\tools; %ADT_HOME%\tools;%ADT_HOME%\platform-tools\platform-tools\tools;    %ADT_HOME%\tools;;%GIT_HOME%\cmd;

It's ridiculous. So if you need to edit your PATH; I strongly suggest you copy the whole string into a document and edit it from there. Copy and paste it back into the tiny text box, and apply. But save your original PATH in case you mess something up.

The next thing to do is download Android API-19 using the android SDK manager, you may need to run it as an administrator.

If all of that works, you should be able to open Git bash and run these two commands

cordova platform add android

cordova build

If it throws an error, it should give some indication as to where your problem is. Likely an Environment Variable is pointed to the wrong folder, or something isn't installed. For example if it mentions Android-20, you need to download Android API-20.

No comments:

Post a Comment