Ok. It's time to create your own project for our sample App "Confuse-Text". First read the developers instructions here! Then select File-->New-->Android Project. Once you have created the project, use the package explorer pane to expand the src, expand the package name and click on the default java class file. That's it. You are ready to code!
F.A.Q.
What is the Project name?
The name of the folder that will hold the project. In our case I named the project confusetext.
What is the Application name?
The name that will appear on the Android phone. In our case I named the App Confuse-Text
How do I choose the package name?
Choose a name hierarchy that uniquely identifies you and then the application (reverse order and lower case only). I originally used "com.google.sites.site.jalcomputing". Then I added a hierarchy that identifies our sample app as "android.app". So the full package name was: "com.google.sites.site.jalcomputing.android.app".
(This strategy does not allow an app to be uploaded to the Android Market. You could try to use the refactor tool in Eclipse to rename the package.)
What is the fully qualified name of the class?
The fully qualified name is a combination of the package name and the class name so for the class ConfuseText the fully qualified name will be: "com.google.sites.site.jalcomputing.android.app.ConfuseText"
What is the Create Activity parameter?
This will determine the name of the base class in your project. I entered Create Activity: "ConfuseText" which created: public class ConfuseText extends Activity {...}
I entered Android 2.2 and then 2.2 as the Min SDK Version and I got a compiler error. What happened?
You need to enter the integer value of the API Level, not the Platform version number. I entered the integer 8 which corresponds to Android 2.2.
What are all these files in my Confuse-Text project?
1. The default java class file ConfuseText.java at src-->com.google.sites.site.jalcomputing.android.app-->ConfuseText.java is the code entry point for your application.
package com.google.sites.site.jalcomputing.android.app;
import android.app.Activity;
import android.os.Bundle;
public class ConfuseText extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Figure 1. The main class for your application, ConfuseText.java
2. The default linear layout xml file main.xml at res-->layout-->main.xml is the xml layout file that describes the appearance of your app. This simplifies application maintenance by separating out the view (presentation code as xml) from the Controller (Activity) and model (algorithm class).
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ConfuseText!</string>
<string name="app_name">Confuse Text</string>
</resources>
Figure 2. The xml layout file for your application, main.xml.
3. The default string resource file strings.xml at res-->values-->string.xml is the xml file that contains the hard coded string values used by your app. This greatly simplifies application wide changes to string values by placing all of the text in a single file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ConfuseText!</string>
<string name="app_name">Confuse Text</string>
</resources>
Figure 3. The default string resource file, strings.xml.
4. The project manifest file AndroidManifest.xml at res-->AndroidManifest.xml describes the components used by the application, names the libraries to be linked and identifies permissions required by the app. If your application launches a second activity, you will need to modify this file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.sites.site.jalcomputing.android.app"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ConfuseText"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Figure 4. The manifest file AndroidManifest.xml, used by the runtime to check for the availability of needed components and permissions.
5. The read only default properties file at res-->default.properties includes the project settings such as the project target to be used by the Ant build system and is used in version control. It should not be edited manually.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-8
Figure 5. The default properties file, default.properties, used by Ant.
6. The configuration file at res-->proguard.cfg is used by the ProGuard tool that "shrinks, optimizes, and obfuscates your code" in the release build. Occasionally you may need to edit this file if ProGuard decides to remove needed code generating a ClassNotFoundException in the release build.
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
Figure 6. The configuration file for ProGuard, a code obfuscation tool.
7. The auto-generated file R.java at gen--> com.google.sites.site.jalcomputing.android.app is generated from the xml files in the res folder. If there are errors in the xml files, the R.java file will not be auto-generated and you cannot "run" your app in the IDE. If you delete this file, it will be regenerated. If the file is not regenerated there probably is an error in an xml file that prevents the generation of a valid R.java file.
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.google.sites.site.jalcomputing.android.app;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
Figure 7. The auto-generated R.java file generated from the xml files in the resources folder.