Showing posts with label windows 7. Show all posts
Showing posts with label windows 7. Show all posts

2014-01-05

Android SDK Setup Pitfalls in Windows 7 without Eclipse

I'm delving into Android development for the first time and ran into some trouble during the SDK setup on my Windows 7 machines. I wanted to use an IDE other than Eclipse, which complicated things somewhat. For example, if you're not using the Eclipse-ADT (Android Development Tools) bundle, you'll be keeping a lot more cozy with the command line. But I followed the provided platform-specific documentation as closely as possible and still ran into snags that cost me a lot of time. Hopefully by piecing together a write-up of my experience I can cement the process in my mind and consolidate some of this information to save others time during their setup.

Resources, Downloads, Installation


First, if you are new to Android development, I recommend visiting and bookmarking the Android developer home page. From there you can (sorta) easily navigate to all the resources and information you need to get started. If the installation of the SDK goes smoothly (which I hope to help facilitate with this post), you can follow their tutorial and probably get a "hello, world" Android app up and running inside an hour.

Start by installing the Android SDK (not the Eclipse-ADT bundle). Following the documentation for the SDK installer and resource download went smoothly for me. The only thing to mention is that there is some finagling you have to do to get all the licenses accepted in the SDK Manager if you want any of the options that aren't specified in the documentation (there are multiple methods of accepting certain licenses for some reason).

Using a Batch Supportive CLI


One thing they won't tell you in the docs that they should, is that the command line input they give you includes some batch file execution. When I was going through this process, I was using Git Bash. This was causing me all kinds of problems because the syntax you use to execute batch files in Git Bash or other third party shells is different from that you'd use at the Windows 7 command line. I kept getting android: command not found and I didn't understand why, because I had correctly added all my directories to the Windows PATH variable and everything. Even once I'd figured out that these were batch files and needed different syntax to be run, it took me a while to realize that the reason the execution was failing wasn't just because my syntax was wrong, but because the Git Bash just doesn't fully support batch file execution.

In short, the Android documentation assumes you're using a CLI that provides full support of Windows batch file execution.

Setting Up an Android Virtual Device and Emulation


Skip this if you only plan to test on physical Android devices. I wanted to test virtually so I had to set up the emulator. For the emulator to run on Windows 7, you can't give your virtual Android device too much memory or the emulator will crash. I was getting errors from emulator_arm.exe when trying to run my virtual Nexus 7. Reducing the allocated memory on the virtual device from 1024 to 512 allowed me to run the emulator with no trouble (though I'm not confident this provides a realistic testing environment down the road).

Also note that when loading the emulator, the virtual device's boot time may be quite long. I have a reasonably quick laptop with SSD, 8GB RAM, yadda yadda yadda, and it still took a couple of minutes to boot the emulator. Be patient, don't panic.

Windows Environment Variables, Including JAVA_HOME


Throughout this process, you may well find yourself working with Windows environment variables, including the PATH variable, at length. Be careful, you can do some pretty annoying damage to your system if you are careless in there. Follow directions carefully and correctly to make sure everything will work and you don't lose any important system information that may already have been added to any Windows environment variables.

This is a preemptive note for the next section, but important nonetheless. There is a command line application you'll need by Apache called Ant. It's a command line build tool for Java projects. When installing Ant, make sure you add that to your Windows PATH variable. Otherwise, when you try to run Ant you'll just get the classic 'ant' is not recognized as a an internal or external command error. Next, you need to make sure a Windows environment variable called JAVA_HOME is correctly pointing to the location of the JDK (Java Development Kit) on your system, because Ant uses the JDK. If the JAVA_HOME variable doesn't exist, just create it (I had to).

Installing an App onto an Android Device


At long last, I had the SDK all set up and I'd gotten the sample "hello, world" app built. To install an app onto a device (virtual or physical) for testing, the documentation first tells you to navigate to your project root directory and enter ant debug at the command line. They don't tell you what this does, why it's important, or most critically, that Apache Ant (which you can download and learn more about here), may not even be installed on your system, and is essential to the tutorial in the documentation. Now you know.

Finally


Now I'm running Android apps in emulation. My next step is to try running the "hello, world" app on a physical device, then I'm off to the races. Hope you found something here to help you along the way on your Android journey! And as always...

Thanks for reading!
- Steven Kitzes

2013-07-08

Updating Environment Variables in Windows

This weekend I installed the Java Runtime Environment and the Java Development Kit onto my desktop and my laptop, both running identical Windows 7 environments. The installation onto the desktop went without a hitch. I ran both the JRE and JDK installers, got the JetBrains IntelliJ IDEA Java IDE up and running, and tried executing my first Java 'Hello World' program from the console. Shockingly, this worked on the very first try with no errors, and from the Git Bash, no less! This was such a pleasant surprise and unexpected result that it even prompted me to rename my dev blog to 'Unexpected Result'!

But for whatever reason, after going through all the same steps on my laptop, I couldn't seem to get Java to run from Git Bash. Upon checking my environment variable (typing env | grep PATH in Git Bash), I discovered that the JDK directory somehow didn't seem to have been added!

It turns out the solution was a simple matter of closing the Git Bash and reopening it! When a PATH variable change is registered, that change won't be visible to any running instances of Git Bash. It seems that Git Bash reads the PATH variable from Windows one time only, when the CLI is launched, and doesn't refresh it until the CLI is closed and launched again. This is true of other command line interfaces in Windows, as well (such as the Windows command prompt).

So if you've just added something new to a Windows environment variable, and it doesn't seem to be working from your CLI, make sure you have restarted your CLI after the environment variable was modified and it should be smooth sailing from there!

Thanks for reading!
-- Steven Kitzes