Project 1: Android Studio on Mac or Windows (10 points)

What You Need for This Project

Purpose

Android Studio is Google's software development environment for Android.

It's essential for creating, debugging, and testing Android apps.

Mac OS X Issue

After installing Android Studio, I couldn't start VMware Fusion virtual machines on my Mac--I got this error:
Could not open /dev/vmmon: No such file or directory.
This problem is caused by the Intel Hardware Accelerated Execution Manager (HAXM).

One workaround is to restart the Mac. After a restart, VMware Fusion works.

Another workaround is to unload the Intel HAXM module with this Terminal command:

sudo kextunload -b com.intel.kext.intelhaxm
There are several links at the end of this project explaining Intel HAXM.

Task 1: Installing Android Studio

Note About the S214 Lab

If you use the S214 lab, Android Studio is already installed on the Macs and on the PCs running Ubuntu Linux. You can just skip Task 1:Installing Android Studio and proceed to Task 2: Making an App.

But you'll be dependent on the lab to do future projects, and the lab can get crowded. It'll be a lot more conveneint for you to set this up on your own computer.

Downloading Android Studio

http://developer.android.com/sdk

Follow the instructions on the Web page to download and install Android Studio for your OS. The Mac version is 234 MB in size, but the Windows version is 828 MB.

Missing Java

If you are using a Mac:
Finish the install and launch Android Studio.

A box pops up, asking if you want to import settings from a previous installation. Accept the default selection refusing to do that.

The Setup Wizard launches. Click Next.

If you are using a PC, start the installation process.

In either case, you will probably see a screen saying that you need the Java SDK, as shown below.

Installing Java SDK

If JDK was not detected, as shown above, you need to fix that.

In the Android Studio Setup Wizard, click the blue link.

Download the correct Java SDK for your OS, as shown below.

Install the Java SDK, with the default options.

Resuming the Android Studio Setup

If you are using a Mac, in the Android Studio Setup Wizard, click Previous and then Next. If you are using a PC, cancel the installation and start it from the beginning again.

Install Android Studio with the default options.

Accept all the license agreements, of course.

It's a long process, with a lot of files downloaded and installed.

Task 2: Making an App

Writing an App

When the install finishes, Android Studio launches. If you didn't just install it, click the Start Button (on a Mac, click the Spotlight button in the top right that looks like a magnifying glass) and search for "Android" to launch it.

You should see the "Welcome to Android Studio" screen, as shown below.

On the right side, click "Start a new Android Studio project", as shown below.

In the "New Project" screen, enter an Application name of YOURNAME-hello, as shown below.

Don't use the literal text "YOURNAME" -- replace that with your own name.

Click Next.

The next screen asks which versions of Android you are targeting, as shown below.

Accept the default selection and click Next.

In the "Add an activity to Mobile" screen, accept the default selection of "Blank Activity" as shown below, and click Next.

In the "Choose options for your new file" screen, accept the default selections as shown below, and click Finish.

If you are using Windows, it will spend several minutes "Indexing".

Other messages go by, initializing things and "Building".

When all that stuff is done, a project page appears, as shown below.

If "Windows Firewall" boxes pop up, approve Java to access the Internet.

If a "Tip of the day" pops up, close it.

If a "Rendering problems" box appears, close it.

However, if a "Gradle project sync failed" message appears, as shown above, that means you have errors that matter, probably Java errors.

Resolving Java Errors

On my PC, Java worked! But that is a very rare exception.

Java fails to work most of the time. It is maddening, but there's no way to escape it.

The most common problem is that the Java files are installed in a directory that the application cannot find. It's been this way for many years, and somehow Java never fixes it.

Here's what I did, but your errors will probably be different. Expect this to take time and a lot of Googling.

In my case, there is a yellow bar saying "Gradle project sync failed...", and a pop-up box titled "Language Level Changed", as shown above.

In the pop-up box titled "Language Level Changed", click Yes.

The project reloads. Now the lower pane shows some Java error messages, as shown below.

Open a Terminal window, and execute this command:

/usr/libexec/java_home
The response tells you where Java is installed, as shown below.

On my Mac, Java is installed at

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

In the lower pane of Android Studio, click "Open SDK Settings".

As you can see below, the "JDK location" is wrong.

Copy and paste in the correct location, as shown below.

Then click OK.

Android Studio displays a yellow bar at the top, saying "Gradle sync in progress".

After that, the "Language Level Changed" box pops up again. Click Yes.

Exploring your App

When the Java problems are fixed, your project loads without errors, as shown below.

The left pane shows the files in your app.

A much easier way to control your app is to use the right pane. Click the activity_main.xml tab.

The center now shows the screen of a phone, showing "Hello world!" in tiny letters, as shown above. This is a graphical view of how your app will look on a phone.

Customizing your App

In the upper right of the Android Studio window, in the "Component Tree" section, click "TextView - @string/hello_world".

In the lower right of the Android Studio window, in the Properties section, scroll down to textSize and change the size to 40. Press Enter. The "Hello world" text gets larger, as shown below.

On the phone face, double-click "Hello world".

A little box appears with a "text" field containing "@string/hello_world", as shown below.

Replace the "@string/hello_world" text with this text:

Hello from YOUR NAME

Use your own name, not the literal text "YOUR NAME".

In the "id" field, enter

YOURNAME
Replace "YOURNAME" with your own name, without any embedded spaces, as shown below.

Press Enter.

The phone face should now show the revised message containing your name, as shown below.

Saving a Screen Image

Make sure Your Name is visible on the phone face.

Save a full-desktop image of this screen. On a Mac, press Shift+Commmand+3. On a PC, press Shift+PrntScrn and paste into Paint.

YOU MUST SUBMIT A FULL-SCREEN IMAGE FOR FULL CREDIT!

Paste the image into Paint.

Save the image with the filename "YOUR NAME Proj 1", replacing "YOUR NAME" with your real name.

Turning in your Project

Email the images to cnit.128sam@gmail.com with the subject line: Proj 1 from YOUR NAME

Sources

Android Adventures - Getting Started With Android Studio

stackoverflow: Error:compileSdkVersion android-21 requires compiling with JDK 7

IntelĀ® Hardware Accelerated Execution Manager

Installation Instructions for IntelĀ® Hardware Accelerated Execution Manager - Mac OS X*

Fusion 5 - Could not open devvmmon: No such file or directory.


Last modified 12-20-16