Create the project without Eclipse

I’m a Unix guy. I’d like to create the project with the vi text editor, without using Eclipse at all. See Managing Projects from the Command Line.

The android tool

The program android is in the tools directory. When we installed Eclipse and Android, we put the full pathname of tools into our PATH environment variable. (On my Mac, it was /Users/myname/Development/adt-bundle-mac-x86_64-20130219/sdk/tools.) Open the Terminal app on a Mac or run cmd.exe on a PC.

android --help
android		(Opens the Android SDK Manager window.  You can then close it.)

List the available targets

We have to specify a target number when we create the project. Here are the legal target numbers:

android list targets
Available Android targets:
----------
id: 1 or "android-17"
     Name: Android 4.2.2
     Type: Platform
     API level: 17
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
     ABIs : armeabi-v7a

If you get no list of targets from android list targets, run the command android with no arguments.
Android SDK Manager → Preferences…
☑ Force https://… sources to be fetched with http://…
Install the packages for the target level you want. Then try android list targets again.

Create the project

The project will be named NoEclipse and will be stored in a directory named NoEclipse. I created a directory named /Users/myname/Documents/workspace2 to hold the NoEclipse directory. Why didn’t I simply put the NoEclipse directory into my existing workspace /Users/myname/Documents/workspace? See the last section below.

mkdir /Users/myname/Documents/workspace2
ls -ld /Users/myname/Documents/workspace2		(minus lowercase LD)

The --target number is one of the above id numbers. The continuation character is \ (backslash) in the Mac Terminal application, ^ (caret) in the Windows Command Prompt.

android create project \
	--target 1 \
	--name NoEclipse \
	--path /Users/myname/Documents/workspace2/NoEclipse \
	--activity NoEclipseActivity \
	--package edu.nyu.scps.noeclipse

Created project directory: /Users/myname/Documents/workspace2/NoEclipse
Created directory /Users/myname/Documents/workspace2/NoEclipse/src/edu/nyu/scps/noeclipse
Added file /Users/myname/Documents/workspace2/NoEclipse/src/edu/nyu/scps/noeclipse/NoEclipseActivity.java
Created directory /Users/myname/Documents/workspace2/NoEclipse/res
Created directory /Users/myname/Documents/workspace2/NoEclipse/bin
Created directory /Users/myname/Documents/workspace2/NoEclipse/libs
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/values
Added file /Users/myname/Documents/workspace2/NoEclipse/res/values/strings.xml
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/layout
Added file /Users/myname/Documents/workspace2/NoEclipse/res/layout/main.xml
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/drawable-xhdpi
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/drawable-hdpi
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/drawable-mdpi
Created directory /Users/myname/Documents/workspace2/NoEclipse/res/drawable-ldpi
Added file /Users/myname/Documents/workspace2/NoEclipse/AndroidManifest.xml
Added file /Users/myname/Documents/workspace2/NoEclipse/build.xml
Added file /Users/myname/Documents/workspace2/NoEclipse/proguard-project.txt

We just created a directory named NoEclipse. You probably want to edit the AndroidManifest.xml file in that directory and change the label attribute of the activity element to No Eclipse.

Create the .apk file

We build the “android package” file by running the Java program ant by Apache (Another Neat Tool). It’s not in the tools directory. On my Mac, it’s /usr/bin/ant. It reads the project’s build.xml file, analogous to a Unix Makefile.

cd /Users/myname/Documents/workspace2/NoEclipse
pwd
/Users/myname/Documents/workspace2/NoEclipse
which ant		(on Mac)
/usr/bin/ant
ant -help
ant debug

Buildfile: /Users/myname/Documents/workspace2/NoEclipse/build.xml
BUILD SUCCESSFUL
Total time: 4 seconds
cd bin
pwd
/Users/myname/Documents/workspace2/NoEclipse/bin
ls -l *.apk		(minus lowercase L)
-rw-r--r--  1 myname  mygroup  37116 May 13 12:14 NoEclipse-debug-unaligned.apk
-rw-r--r--  1 myname  mygroup  37125 May 13 12:14 NoEclipse-debug.apk
file NoEclipse-debug.apk
NoEclipse-debug.apk: Zip archive data, at least v2.0 to extract
unzip -l NoEclipse-debug.apk
Archive:  NoEclipse-debug.apk
  Length     Date   Time    Name
 --------    ----   ----    ----
      708  05-13-13 12:14   res/layout/main.xml
     1356  05-13-13 12:14   AndroidManifest.xml
     1452  05-13-13 12:14   resources.arsc
     9193  05-13-13 12:14   res/drawable-hdpi/ic_launcher.png
     2658  05-13-13 12:14   res/drawable-ldpi/ic_launcher.png
     5057  05-13-13 12:14   res/drawable-mdpi/ic_launcher.png
    14068  05-13-13 12:14   res/drawable-xhdpi/ic_launcher.png
     2116  05-13-13 12:14   classes.dex
      672  05-13-13 12:14   META-INF/MANIFEST.MF
      725  05-13-13 12:14   META-INF/CERT.SF
      776  05-13-13 12:14   META-INF/CERT.RSA
 --------                   -------
    38781                   11 files

Launch the emulator

android avd

Select an emulator and press Start… and then Launch.

adb devices
List of devices attached
emulator-5554	device

Run the .apk file

Specify the serial number of the emulator. The aligned and unaligned .apk files both ran successfully.

adb -s emulator-5554 install /Users/myname/Documents/workspace2/NoEclipse/bin/NoEclipse-debug.apk
1422 KB/s (37125 bytes in 0.025s)
	pkg: /data/local/tmp/NoEclipse-debug.apk
Success

Now touch the icon for the app in the emulator.

Open the project in Eclipse

Now let’s throw in the towel and import the project into Eclipse. A project created by Eclipse contains two files named .project and .settings. Our project does not have these files, so our project is not an “existing project”. The following does not work.
File → Import… → General → Existing Projects into Workspace

Here’s what does work.
File → New → Project… → Android → Android Project from Existing Code
Next
Root Directory: /Users/myname/Documents/workspace2/NoEclipse

Finish

Eclipse creates the directory /Users/myname/Documents/workspace/NoEclipse and copies the project into it. If the project had already been in /Users/myname/Documents/workspace/NoEclipse, Eclipse would have given us the error message “overlaps the location of another project” when we try to import it into Eclipse.