Creating an Android Project

Appportunity

Build your own Android App Dev Empire

Get Instant Access

To create an Android project, you must use the android tool. When you create a new project with android, it will generate a project directory with some default application files, stub files, configuration files and a build file.

Creating a new Project

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:

android create project \ --target <target ID> \ --name <your project name> \

--path /path/to/your/project \ --activity <your activity name> \ --package <your package namespace>

android create project \

--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.

• 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.

• 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 (discussed later). So you need access between your project solution and the tools / folder.

• 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, execute: android list targets.

• 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 a the name.

• package is the package namespace for your project, following the same rules as for packages in the Java programming language. Here's an example:

Caution: You should refrain from moving the location of the SDK directory, because this will break the build scripts. (They will need to be manually updated to reflect the new SDK location before they will work again.)

Updating a project

If you're upgrading a project from an older version of the Android SDK or want to create a new project from existing code, use the android update project command to update the project to the new development environment. You can also use this command to revise the build target of an existing project (with the —target option) and the project name (with the —name option). Theandroid tool will generate any files and folders (listed in the previous section) that are either missing or need to be updated, as needed for the Android project.

• 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, execute: android list targets.

• path is the location of your project directory.

• name is the name for the project. This is optional—if you're not changing the project name, you don't need this. Here's an example:

android update project --name MyApp --target 2 --path ./MyAppProject

Was this article helpful?

0 0

Post a comment