The ADT plugin Android Development Tools gives a New Project Wizard that can help to create a new Android project.
Creating new project in Android using project wizard:
1: Select File > New > Project.
2: Select Android > Android Project, and click Next.
Figure 1: Creating Android Project
3: Select the contents for the project in next window:
Figure 2: Choosing locate
- Input a Project Name to Project Name edit field.
- Next, select Create new project in workspace under contents. Then, select your project workspace location (Uncheck Use default location, do it just). Then, Go next.
- In Select Build Target window, select an Android target to be used as the project's Build Target.
- Under Properties, fill in all necessary fields.
- Enter an Application name. This is the human-readable title for your application — the name that will appear on the Android device.
- Enter a Package name. This is the package namespace (following the same rules as for packages in the Java programming language) where all your source code will reside.
- Select Create Activity (optional, of course, but common) and enter a name for your main Activity class.
- Enter a Min SDK Version. This is an integer that indicates the minimum API Level required to properly run your application. Entering this here automatically sets the minSdkVersion attribute in the <uses-sdk> of your Android Manifest file. If you're unsure of the appropriate API Level to use, copy the API Level listed for the Build Target you selected in the Target tab.
This will be the name of the folder where your project is created in your workspace.
Figure 3: Choosing SDK to target
The Build Target specifies which Android platform you'd like your application built against. Unless you know that you'll be using new APIs introduced in the latest SDK, you should select a target with the lowest platform version possible.
Note: You can change your the Build Target for your project at any time: Right-click the project in the Package Explorer, select Properties, select Android and then check the desired Project Target.
Figure 4: Application Info
4. Click Finish. New Project is created completely now.
Tip: You can also start the New Project Wizard from the New icon in the toolbar.
Once you complete the New Project Wizard, ADT creates the following folders and files in your new project automatically:
- src/: Includes your stub Activity Java file. All other Java files for your application go here.
- gen/: This contains the Java files generated by ADT, such as your R.java file and interfaces created from AIDL files.
- / (e.g., Android 3.2/): Includes the android.jar file that your application will build against. This is determined by the build target that you have chosen in the New Project Wizard.
- assets/: This is empty. You can use it to store raw asset files.
- bin/: This is empty. After built, binary exec file is placed here.
- res/: A folder for your application resources, such as drawable files, layout files, string values, etc.
- AndroidManifest.xml: The Android Manifest for your project.
- project.properties: This file contains project settings, such as the build target. This files is integral to the project, as such, it should be maintained in a Source Revision Control system. It should never be edited manually - to edit project properties, right-click the project folder and select "Properties".
Figure 5: Project folders
The creation of the new project using Project Wizard is finished.
To create a new project in Android using command window:
If you're starting a new project, use the android create project command to generate all the necessary files and folders.
To create a new Android project, open a command-line, navigate to the tools/ directory of your SDK and run:
Listing 1: Creating the new Android Project
android create project --target <target_ID> --name <your_project_name> --path path/to/your/project --activity <your_activity_name> --package <your_package_namespace>
- target is the "build target" for your application. It corresponds to an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs.
- name is the name for your project. This is optional. If provided, this name will be used for your .apk filename when you build your application.
- path is the location of your project directory. If the directory does not exist, it will be created for you.
- activity is the name for your default Activity class. This class file will be created for you inside <path_to_your_project>/src/<your_package_namespace_path>/ . This will also be used for your .apk filename unless you provide the name.
- package is the package namespace for your project, following the same rules as for packages in the Java programming language.
Listing 2: Here's an example of the Android project
android create project --target 1 --name MyAndroidApp --path ./MyAndroidAppProject --activity MyAndroidAppActivity --package com.example.myandroid
The tool generates the following files and directories:
- AndroidManifest.xml - The application manifest file, synced to the specified Activity class for the project.
- build.xml - Build file for Ant.
- default.properties - Properties for the build system. Do not modify this file.
- build.properties - Customizable properties for the build system. You can edit this file to override default build settings used by Ant and provide a pointer to your keystore and key alias so that the build tools can sign your application when built in release mode.
- src/your/package/namespace/ActivityName.java - The Activity class you specified during project creation.
- bin/ - Output directory for the build script.
- gen/ - Holds Ant-generated files, such as R.java.
- libs/ - Holds private libraries.
- res/ - Holds project resources.
- src/ - Holds source code.
- tests/ - Holds a duplicate of all-of-the-above, for testing purposes.
Once you've created your project, you're ready to begin development. You can move your project folder wherever you want for development, but keep in mind that you must use the Android Debug Bridge (adb) — located in the SDK tools/ directory - to send your application to the emulator. So you need access between your project solution and the tools/ folder.
Creating an Android Virtual Device (AVD) in Android Eclipse:
An Android Virtual Device (AVD) is a device configuration for the emulator that allows you to model real world devices. In order to run an instance of the emulator, you must create an AVD.
To create an AVD from Eclipse:
- Select Window > Android SDK and AVD Manager, or click the Android SDK and AVD Manager icon in the Eclipse toolbar.
- In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD.
- Fill in the details for the AVD.
- Click Create AVD: Your AVD is now ready and you can either close the SDK and AVD Manager, create more AVDs, or launch an emulator with the AVD by selecting a device and clicking Start.
Give it a name, a platform target, an SD card size, and a skin (HVGA is default).
Note: Be sure to define a target for your AVD that satisfies your application's Build Target (the AVD platform target must have an API Level equal to or greater than the API Level that your application compiles against).
How to Running Your Application
Running your application from Eclipse will usually require just a couple clicks, whether you're running it on the emulator or on an attached Android Phone device.
The information below describes how to get set up and run your application from Eclipse.
Running on the emulator
Before you can run your application on the Android Emulator, you must create an AVD.
To run (or debug) your application, select Run > Run (or Run > Debug) from the Eclipse menu bar.
The ADT plugin will automatically create a default launch configuration for the project.
Eclipse will then perform the following:
- Compile the project (if there have been changes since the last build).
- Create a default launch configuration (if one does not already exist for the project).Install and start the application on an emulator (or device), based on the Deployment Target defined by the run configuration.
- By default, Android run configurations use an "automatic target" mode for selecting a device target.
If debugging, the application will start in the "Waiting For Debugger" mode.
Once the debugger is attached, Eclipse will open the Debug perspective.
To set or change the launch configuration used for your project, use the launch configuration manager.
Be certain to create multiple AVDs upon which to test your application.
You should have one AVD for each platform and screen type with which your application is compatible. For instance, if your application compiles against the Android 3.2(API Level 13) platform, you should create an AVD for each platform equal to and greater than 1.5 and an AVD for each screen type you support, then test your application on each one.
Figure 6: Project Done
Running on a device
Before you can run your application on a device, you must perform some basic setup for your device:
- Declare your application as debuggable in your manifest
- Enable USB Debugging on your device
- Ensure that your development computer can detect your device when connected via USB
Once set up and your device is connected via USB, install your application on the device by selecting Run > Run (or Run > Debug) from the Eclipse menu bar.
Wait for the next tutorial to learn more on the implementation of application on the device. See you soon.