-
Notifications
You must be signed in to change notification settings - Fork 2
Android 2
For this assignment, you must:
- Create a folder called
and2
in your course repository. - Install Apache Ant on your computer.
- Setup an Android Device or Virtual Device for testing.
- Set an Android Build Target.
- Create an Android project.
- Modify your app content.
- Create
~/322/.gitignore
if it doesn't already exist. - Create a
README.md
file in yourand2
folder. - In the README, describe what you learned and did.
- Push your changes to your course repository.
The purpose of this assignment is to learn how to use Android SDK command line tools to build and test Android applications.
These instructions were derived from Building Your First App within the Android SDK documentation.
Video demonstration of this assignment under OS X by Tyrice Clark
WARNING: this video may not be consistent with current instructions for the assignment; make sure you make adjustments.
Create directory ~/322/and2
. At the end of the assignment, this folder will contain the following files and subfolders.
- README.md
- hello
If you have an Android device that you can use for testing, then configure your phone to test apps you are developing. Depending on the version of Android that you are using, you will do something like the following.
- Under Settings ... Developer Options, turn on usb Debugging.
- Under Settings ... Security, allow installation of apps from sources other than the Play Store.
If you don't have an Android device, then you will need to use the emulator that comes with the Android SDK.
These instructions assume that you have the most recent version of Android and it is "android-18". To check this, run the following command.
android list targets
If you see a version of Android later than "android-18", then use that in place of "android-18" in these instructions.
In ~/322/and2
, run the following command to create an Android project named "hello". (In Windows, replace '' with '^'. These symbols in script files indicate line continuation.)
android create project \
--target android-18 \
--name hello \
--path ./hello \
--activity MainActivity \
--package cse322.hello
Ant is an Apache Foundation project that is widely used for building Java code, so it is not surprising that the Android SDK uses Ant.
Ant depends on the Java development kit (JDK). Run the following command to see if the JDK is installed on your system.
javac -version
If the above command is "not found" then you need to install the JDK. It is sufficient to install the JDK Standard Edition (JDK SE).
Go to the Apache Ant website, read a little of the documentation to get more familiar with it, and download and install it.
Ant is a command line tool. After installing Ant, you can check to see if it runs.
ant -version
If the command is not found you should try 2 things. First, close your terminal window and open a new terminal window to make sure your environment is current, then try the command again. Second, modify your system path to include a path to the ant executable. If you do this, make sure you close and reopen a terminal window to make sure the environment is current.
If the command is found, but ant complains about not finding something in a JDK, then create an environmental variable named JAVA_HOME that points to the location of the JDK folder in your system. After setting this environmental variable, close and reopen your terminal window to make sure the environment is current.
The ant command looks for a file with the name build.xml that contains build targets. If a default target is specified in build.xml, then ant will run it. To run a specific target, specify the name of the target as an argument to the ant command. The following is an example:
ant clean
clean
is a common target that is found in build files;
its purpose is to delete generated files, such as java class files.
To see a list of all targets in a build file, run the following.
ant -projecthelp
If get a "command not found" message when you try to run ant, it means that the folder containing the Ant executable is not in your system path. To solve this problem, add this folder to your system path.
Add the following as a child to the root element of hello/AndroidManifest.xml
. If you don't understand XML and what a root element
is, then you should familiarize yourself with the basic ideas of XML.
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
Change the app name in the following file from MainActivity to Hello322.
hello/res/values/strings.xml
Open ~/322/and2/hello/local.properties in a text editor and change the value of sdk.dir to point to the location you placed the android SDK.
Build the app.
cd ~/322/and2/hello
ant debug
If you have an Android device to use for testing, then connect it to the computer by USB cable. Otherwise, start an instance of the emulator through the Android virtual device manager. (Run android avd
and allow the emulator a lot of time to initialize.)
Whether you are using a real device or emulator, install the app with the following command.
ant installd
If you are on Windows and the system can not find the device, then this comment might help.
Launch the app in the android device to test that it runs.
Modify hello/res/layout/main.xml
so that the app displays "Hello 322!".
Recompile the code and reinstall the app.
ant debug
ant installd
Before committing your work to the repository, add the following lines to ~/322/.gitignore
. These are derived files that should not be stored in the repository.
/and2/hello/local.properties
/and2/hello/bin
/and2/hello/gen
If ~/322/.gitignore
doesn't exist, then create it with a text editor. Make sure you add this file to your repository.
Add a statement to ~/322/and2/README.md
that describes how successful you were completing this assignment.
Push changes to your files and folders to the remote repository for the course.