diff --git a/docs/html/images/tools/studio-androidtest-folder.png b/docs/html/images/tools/studio-androidtest-folder.png new file mode 100644 index 0000000000000..6881741157fe3 Binary files /dev/null and b/docs/html/images/tools/studio-androidtest-folder.png differ diff --git a/docs/html/tools/projects/index.jd b/docs/html/tools/projects/index.jd index 439d3be3b9e79..d9456f83dbbc1 100644 --- a/docs/html/tools/projects/index.jd +++ b/docs/html/tools/projects/index.jd @@ -1,4 +1,4 @@ -page.title=Managing Projects +page.title=Managing Projects Overview @jd:body
@@ -6,211 +6,317 @@ page.title=Managing Projects

In this document

    -
  1. Android Projects
  2. +
  3. Android Project Files
  4. +
  5. Android Application Modules
  6. -
  7. Library Projects +
  8. Library Modules
    1. Development considerations
  9. -
  10. Test Projects
  11. +
  12. Test Modules
  13. -
  14. Testing a Library Project
  15. +
  16. Testing a Library Module
-

Projects act as containers for storing things such as code and resource files. The SDK tools - expect your projects to follow a specific structure so it can compile and package your - application correctly, so it is highly recommended that you create them with Eclipse and ADT or - with the android tool on the command line. There are three types of projects, and - they all share the same general structure but differ in function:

+

An Android project contains everything that defines your Android app, from app + source code to build configurations and test code. The SDK tools require that your projects + follow a specific structure so it can compile and package your application correctly. + If you're using Android Studio, it takes care of all this for you.

+ +

A module is the first level of containment within a project that encapsulates + specific types of source code files and resources. There are several types of modules + with a project:

-
Android Projects
-
An Android project is the container for your application's source code, resource files, and - files such as the Ant build and Android Manifest file. An application project is the main type - of project and the contents are eventually built into an .apk file that you install on a - device.
+
Android Application Modules
-
Test Projects
+
An Android Application Module is the container for your application's source code, resource + files, and application level settings, such as the module-level build file, resource files, and + Android Manifest file. The application module contents are eventually + built into the .apk file that gets installed on a device.
-
These projects contain code to test your application projects and are built into - applications that run on a device.
+
Test Modules
-
Library Projects
+
These modules contain code to test your application projects and are built into + test applications that run on a device. By default, Android Studio creates the + androidTest module for inserting JUnit tests.
-
These projects contain shareable Android source code and resources that you can reference +
Library Modules
+ +
These modules contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. - Library projects cannot be installed onto a device, however, they are + Library modules cannot be installed onto a device, however, they are pulled into the .apk file at build time.
+ + +
App Engine Modules
+ +
Android Studio lets you easily add a cloud backend to your application. A backend allows you + to implement functionality such as backing up user data to the cloud, serving content to client + apps, real-time interactions, sending push notifications through Google Cloud Messaging for + Android (GCM), and more. App Engine modules are App Engine java Servlet Module for backend + development, App Engine java Endpoints Module to convert server-side Java code annotations into + RESTful backend APIs, and App Engine Backend with Google Cloud Messaging to send push notifications + from your server to your Android devices.
+
-

When you use the Android development tools to create a new project, the essential files and - folders will be created for you. There are only a handful of files and folders generated for you, - and some of them depend on whether you use the Eclipse plugin or the {@code android} tool to - generate your project. As your application grows in complexity, you might require new kinds of +

When you use the Android development tools to create a new project and the module, the essential files + and folders will be created for you. There are only a handful of files and folders generated for you, + and some of them depend on whether you use Android Studio or the {@code android} tool to + generate your module. As your application grows in complexity, you might require new kinds of resources, directories, and files.

-

Android Projects

+

Note: Project folders and files apply across the entire Android +project and override similar module file settings.

-

Android projects are the projects that eventually get built into an .apk file that you install - onto a device. They contain things such as application source code and resource files. - Some are generated for you by default, while others should be created if - required. The following directories and files comprise an Android project:

+ + + +

Android Project Files

+ +

Android Studio project files and settings provide project-wide settings that apply across all + modules in the project.

+ +
+
.idea
+ +
Directory for IntelliJ IDEA settings.
+ + +
app
+ +
Application module directories and files.
+ + +
build
+ +
This directory stories the build output for all project modules.
+ + +
gradle
+ +
Contains the gradler-wrapper files.
+ + +
.gitignore
+ +
Specifies the untracked files that Git should ignore.
+ + +
build.gradle
+ +
Customizable properties for the build system. You can edit this file to specify the default + build settings used by the application modules and also set the location of your keystore and key alias + so that the build tools can sign your application when building in release mode. This file is + integral to the project, so maintain it in a source revision control system.
+ +
gradle.properties
+ +
Project-wide Gradle settings.
+ + +
gradlew
+ +
Gradle startup script for Unix.
+ + +
gradlew.bat
+ +
Gradle startup script for Windows.
+ +
local.properties
+ +
Customizable computer-specific properties for the build system, such as the path to the SDK + installation. Because the content of the file is specific to the local installation of the SDK, + the local.properties should not be maintained in a source revision control system.
+ + +
.iml
+ +
Module file created by the IntelliJ IDEA to store module information.
+ +
settings.gradle
+ +
Specifies the sub-projects to build.
+ +
+ + +

Android Application Modules

+ +

Android Application Modules are the modules that eventually get built into the .apk + files based on your build settings. They contain things such as application source code and resource + files. Most code and resource files are generated for you by default, while others should be created if + required. The following directories and files comprise an Android application module:

-
src/
-
Contains your stub Activity file, which is stored at - src/your/package/namespace/ActivityName.java. All other source code - files (such as .java or .aidl files) go here as well.
+
build/
-
bin/
+
Contains build folders for the specified build variants. Stored in the main application module.
-
Output directory of the build. This is where you can find the final .apk file and other - compiled resources.
- -
jni/
- -
Contains native code sources developed using the Android NDK. For more information, see the - Android NDK documentation.
- -
gen/
- -
Contains the Java files generated by ADT, such as your R.java file and - interfaces created from AIDL files.
- -
assets/
- -
This is empty. You can use it to store raw asset files. Files that you save here are - compiled into an .apk file as-is, and the original filename is preserved. You can navigate this - directory in the same way as a typical file system using URIs and read files as a stream of - bytes using the {@link android.content.res.AssetManager}. For example, this is a good - location for textures and game data.
- -
res/
- -
- Contains application resources, such as drawable files, layout files, and string values. See - Application Resources for more - information. - -
-
anim/
- -
For XML files that are compiled into animation objects. See the Animation resource - type.
- -
color/
- -
For XML files that describe colors. See the Color Values resource - type.
- -
drawable/
- -
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe - Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or - focused). See the Drawable resource type.
- -
layout/
- -
XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.
- -
menu/
- -
For XML files that define application menus. - See the Menus - resource type.
- -
raw/
- -
For arbitrary raw asset files. Saving asset files here instead of in the - assets/ directory only differs in the way that you access them. These files - are processed by aapt and must be referenced from the application using a resource - identifier in the {@code R} class. For example, this is a good place for media, such as MP3 - or Ogg files.
- -
values/
- -
For XML files that are compiled into many kinds of resource. Unlike other resources in - the res/ directory, resources written to XML files in this folder are not - referenced by the file name. Instead, the XML element type controls how the resources is - defined within them are placed into the {@code R} class.
- -
xml/
- -
For miscellaneous XML files that configure application components. For example, an XML - file that defines a {@link android.preference.PreferenceScreen}, {@link - android.appwidget.AppWidgetProviderInfo}, or Searchability - Metadata. See Application Resources - for more information about configuring these application components.
-
-
libs/
-
Contains private libraries.
+
Contains private libraries. Stored in the main application module.
-
AndroidManifest.xml
-
The control file that describes the nature of the application and each of its components. - For instance, it describes: certain qualities about the activities, services, intent receivers, - and content providers; what permissions are requested; what external libraries are needed; what - device features are required, what API Levels are supported or required; and others. See the - AndroidManifest.xml - documentation for more information
-
project.properties
-
This file contains project settings, such as the build target. This file is integral to - the project, so maintain it in a source revision control system. To edit project - properties in Eclipse, right-click the project folder and select - Properties.
+
src/
-
local.properties
+
Contains your stub Activity file, which is stored at + src/main/java//ActivityName>.java. All other source + code files (such as .java or .aidl files) go here as well.
-
Customizable computer-specific properties for the build system. If you use Ant to build - the project, this contains the path to the SDK installation. Because the content of the file - is specific to the local installation of the SDK, the local.properties should not -be maintained in a source revision control system. If you use Eclipse, this file is not -used.
+
+
androidTest/
-
ant.properties
+
Contains the instrumentation tests. For more information, see the + Android Test documentation.
-
Customizable properties for the build system. You can edit this file to override default - build settings used by Ant and also provide the location of your keystore and key alias so that - the build tools can sign your application when building in release mode. This file is integral - to the project, so maintain it in a source revision control system. If you use Eclipse, this - file is not used.
+
main/java/com.>project<.>app<
-
build.xml
+
Contains Java code source for the app activities.
+ +
main/jni/
+ +
Contains native code using the Java Native Interface (JNI). For more information, see the + Android NDK documentation.
+ +
main/gen/
+ +
Contains the Java files generated by Android Studio, such as your R.java file and + interfaces created from AIDL files.
+ +
main/assets/
+ +
This is empty. You can use it to store raw asset files. Files that you save here are + compiled into an .apk file as-is, and the original filename is preserved. You can + navigate this directory in the same way as a typical file system using URIs and read files as a + stream of bytes using the {@link android.content.res.AssetManager}. For example, this is a good + location for textures and game data.
+ +
main/res/
+ +
Contains application resources, such as drawable files, layout files, and string values + in the following directories. See + Application Resources for more + information. + +
+
anim/
+ +
For XML files that are compiled into animation objects. See the Animation resource + type.
+ +
color/
+ +
For XML files that describe colors. See the Color Values resource + type.
+ +
drawable/
+ +
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe + Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or + focused). See the Drawable resource type.
+ +
layout/
+ +
XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.
+ +
menu/
+ +
For XML files that define application menus. + See the Menus + resource type.
+ +
raw/
+ +
For arbitrary raw asset files. Saving asset files here is essentially the same as + saving them in the assets/ directory. The only difference is how you + access them. These files + are processed by aapt and must be referenced from the application using a resource + identifier in the {@code R} class. For example, this is a good place for media, such as MP3 + or Ogg files.
+ +
values/
+ +
For XML files that define resources by XML element type. Unlike other resources in + the res/ directory, resources written to XML files in this folder are not + referenced by the file name. Instead, the XML element type controls how the resources + defined within the XML files are placed into the {@code R} class.
+ +
xml/
+ +
For miscellaneous XML files that configure application components. For example, an XML + file that defines a {@link android.preference.PreferenceScreen}, {@link + android.appwidget.AppWidgetProviderInfo}, or + + Searchability Metadata. See + Application Resources + for more information about configuring these application components.
+ +
+ +
AndroidManifest.xml
+ +
The control file that describes the nature of the application and each of its components. + For instance, it describes: certain qualities about the activities, services, intent receivers, + and content providers; what permissions are requested; what external libraries are needed; what + device features are required, what API Levels are supported or required; and others. See the + AndroidManifest.xml + documentation for more information
+ +
+ +
.gitignore/
+ +
Specifies the untracked files ignored by git.
+ +
app.iml/
+ +
IntelliJ IDEA module
+ +
build.gradle
+ +
Customizable properties for the build system. You can edit this file to override default + build settings used by the manifest file and also set the location of your keystore and key alias + so that the build tools can sign your application when building in release mode. This file is + integral to the project, so maintain it in a source revision control system.
+ +
proguard-rules.pro
+ +
ProGuard settings file.
-
The Ant build file for your project. This is only applicable for projects that - you build with Ant.
-

Library Projects

+ + +

Library Module

-

An Android library project is a development project that holds shared Android - source code and resources. Other Android application projects can reference the library project +

An Android library module is a development module that holds shared Android + source code and resources. Other Android application modules can reference the library module and, at build time, include its compiled sources in their .apk files. Multiple - application projects can reference the same library project and any single application project - can reference multiple library projects.

+ application modules can reference the same library module and any single application module + can reference multiple library modules.

Note: You need SDK Tools r14 or newer to use the new library - project feature that generates each library project into its own JAR file. + module feature that generates each library module into its own JAR file. You can download the tools and platforms using the Android SDK Manager, as described in Exploring the SDK.

If you have source code and resources that are common to multiple Android projects, you - can move them to a library project so that it is easier to maintain across applications and - versions. Here are some common scenarios in which you could make use of library projects:

+ can move them to a library module so that it is easier to maintain across applications and + versions. Here are some common scenarios in which you could make use of library modules:

-

Structurally, a library project is similar to a standard Android application project. For - example, it includes a manifest file at the project root, as well as src/, - res/ and similar directories. The project can contain the same types of source - code and resources as a standard Android project, stored in the same way. For example, source - code in the library project can access its own resources through its R class.

+

Structurally, a library module is similar to a standard Android application module. For + example, it includes a manifest file at the module root, as well as src/, + res/ and similar directories. The module can contain the same types of source + code and resources as a standard Android module, stored in the same way. For example, source + code in the library module can access its own resources through its R class.

-

However, a library project differs from a standard Android application project in that you +

However, a library module differs from a standard Android application module in that you cannot compile it directly to its own .apk and run it on an Android device. - Similarly, you cannot export the library project to a self-contained JAR file, as you would do + Similarly, you cannot export the library module to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

-

When you build an application that depends on a library project, the SDK tools compile the - library into a temporary JAR file and uses it in the main project, then uses the +

When you build an application that depends on a library module, the SDK tools compile the + library into a temporary JAR file and use it in the main module, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets - priority and that the resource in the library project is not compiled into the application + priority and that the resource in the library module is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

To organize your code further, your application can add references to multiple library - projects, then specify the relative priority of the resources in each library. This lets you + modules, then specify the relative priority of the resources in each library. This lets you build up the resources actually used in your application in a cumulative manner. When two libraries referenced from an application define the same resource ID, the tools select the resource from the library with higher priority and discard the other.

-

Once you have added references to library projects to your Android project, +

Once you have added references to library modules to your Android application module, you can set their relative priority. At build time, the libraries are merged with the application one at a time, starting from the lowest priority to the highest.

-

Library projects can reference other library projects and can import an external library - (JAR) in the normal way.

+

Library modules can reference other library modules and can import an external library + (JAR) in the normal way.

Development considerations

-

As you develop your library project and dependent applications, keep the points listed below +

As you develop your library modules and dependent applications, keep the points listed below in mind:

Test Projects

@@ -365,82 +469,55 @@ be added in a future

Test projects contain Android applications that you write using the Testing and Instrumentation framework. The framework is an extension of the JUnit test framework and adds - access to Android system objects. The file structure of a test project is the same as an - Android project.

+ access to Android system objects.

+ +

The test projects are now automatically part of the app source folder. When a new application + module is created, Android Studio creates the src/androidTest source set. This + source set contains tests for the default configuration and is combined with the debug + build type to generate a test application.

+ + +

Figure 1. androidTest Folder.

+ +

Note: The src/androidTest source set may not be + created for every type of available module template. If this source set is not created, you + can just create it for that module.

+ +

For each product flavor, create a test folder specific to that product flavor.

-
src/
+
src/main/
+
src/androidTest/ -
Includes your test source files. Test projects do not require an Activity .java - file, but can include one.
+
src/productFlavor1/
+
src/testproductFlavor1/
-
gen/
+
src/productFlavor2/
+
src/testproductFlavor2/
-
This contains the Java files generated by ADT, such as your R.java file and - interfaces created from AIDL files.
- -
assets/
- -
This is empty. You can use it to store raw asset files.
- -
res/
- -
A folder for your application resources, such as drawable files, layout files, string - values, etc. See Application - Resources.
- -
AndroidManifest.xml
- -
The Android Manifest for your project. See The AndroidManifest.xml File. Test - Projects have a special - <instrumentation> - element that connects the test project with the application project.
- -
project.properties
- -
This file contains project settings, such as the build target and links to the project being -tested. This file is integral to the project, so maintain it in a source -revision control system. To edit project properties in Eclipse, right-click the project folder -and select Properties.
- -
local.properties
- -
Customizable computer-specific properties for the build system. If you use Ant to build - the project, this contains the path to the SDK installation. Because the content of the file - is specific to the local installation of the SDK, it should not be maintained in a Source - Revision Control system. If you use Eclipse, this file is not used.
- -
ant.properties
- -
Customizable properties for the build system. You can edit this file to override default - build settings used by Ant and provide the location to your keystore and key alias, so that the - build tools can sign your application when building in release mode. This file is integral to - the project, so maintain it in a source revision control system. - If you use Eclipse, this file is not used.
- -
build.xml
- -
The Ant build file for your project. This is only applicable for projects that - you build with Ant.
-

For more information, see the Testing section.

+

The test manifests are always generated so a manifest in a test source set is optional.

+ +

The test applications run against the debug build type. This can be configured + using the testBuildType property in the build file.

-

Testing a Library Project

+

For more information, see the + Testing section.

+ + +

Testing a Library Module

There are two recommended ways of setting up testing on code and resources in a library - project:

+ module:

diff --git a/docs/html/tools/projects/projects-cmdline.jd b/docs/html/tools/projects/projects-cmdline.jd index 29d0e57acac96..f0830fec80541 100644 --- a/docs/html/tools/projects/projects-cmdline.jd +++ b/docs/html/tools/projects/projects-cmdline.jd @@ -118,7 +118,7 @@ android create project \

Updating a Project

-

If you're upgrading a project from an older version of the Android SDK or want to create a new +

If you're up grading 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 @@ -288,7 +288,7 @@ android.library.reference.1=path/to/library_projectC

Building a dependent application

To build an application project that depends on one or more library projects, you can use the - standard Ant build commands and compile modes, as described in Building and Running. The tools compile and merge all libraries referenced by the application as part of compiling the dependent application project. No additional commands or steps are necessary.

diff --git a/docs/html/tools/projects/projects-studio.jd b/docs/html/tools/projects/projects-studio.jd new file mode 100644 index 0000000000000..508253774574b --- /dev/null +++ b/docs/html/tools/projects/projects-studio.jd @@ -0,0 +1,398 @@ +page.title=Managing Projects from Android Studio + +@jd:body + +
+
+

In this document

+ +
    +
  1. Creating an Android Project
  2. +
      +
    1. Create a New Project
    2. +
    3. Select Form Factors and API Level
    4. +
    5. Add an Activity
    6. +
    7. Configure Your App
    8. +
    9. Develop Your App
    10. +
    + +
  3. Creating an Android Module
  4. + +
  5. Setting up a Library Module
  6. + +
  7. Referencing a Library Module
  8. + +
  9. Setting up an App Eng Module
  10. + +
  11. Using the Android Project View
  12. + +
+ +
+
+ + +

Android Studio provides graphical tools for creating and managing Android projects, which +contain everything that define your Android apps, from app source code to build configurations and +test code. Each project contains one or more different types of modules, such as + application modules, library modules, and test modules.

+ +

This guide explains how to create Android projects and different modules using +Android Studio. +For more information about the Android project structure and module types, read Managing Projects Overview.

+ + + +

Creating an Android Project

+ +

Android Studio makes it easy to create Android apps for several form factors, such as phone, +tablet, TV, Wear, and Google Glass. The New Project wizard lets you choose the form factors +for your app and populates the project structure with everything you need to get started.

+ +

Follow the steps in this section to create a project in Android Studio.

+ +

Step 1: Create a New Project

+ +

If you didn't have a project opened, Android Studio shows the Welcome screen. +To create a new project, click New Project.

+ +

If you had a project opened, Android Studio shows the development environment. +To create a new project, click File > New Project.

+ +

The next window lets you configure the name of your app, the package name, and the location +of your project.

+ + +

Figure 1. Choose a name for your project.

+ +

Enter the values for your project then click Next.

+ +

Step 2: Select Form Factors and API Level

+ +

The next window lets you select the form factors supported by your app, such as phone, tablet, +TV, Wear, and Google Glass. The selected form factors become the application modules witin the +project. For each form factor, you can also select the API Level for that app. To get more information, +click Help me choose.

+ + +

Figure 2. Select the API Level.

+ +

The API Level window shows the distribution of mobile devices running each version of Android, +as shown in figure 3. Click on an API level to see a list of features introduced in the corresponding +version of Android. This helps you choose the minimum API Level that has all the features that +your apps needs, so you can reach as many devices as possible. Then click OK.

+ + +

Figure 3. Choose form factors for your app.

+ +

Then, on the Form Factors Window, click Next.

+ + +

Step 3: Add an Activity

+ +

The next screen lets you select an activity type to add to your app, as shown in figure 4. +This screen displays a different set of activities for each of the form factors you selected earlier.

+ + +

Figure 4. Add an activity to your app.

+ +

Choose an activity type then click Next.

+ +

Note: If you choose "Add No Activity", click Finish + to create the project.

+ + +

Step 4: Configure Your Activity

+ +

The next screen lets you configure the activity to add to your app, as shown in figure 5.

+ + +

Figure 5. Choose a name for your activity.

+ +

Enter the activity name, the layout name, and the activity title. Then click +Finish.

+ + +

Step 5: Develop Your App

+ +

Android Studio creates the default structure for your project and opens the development +environment. If your app supports more than one form factor, Android Studio creates a module folder +with complete source files for each of them as shown in figure 6.

+ + +

Figure 6. The default project structure for a mobile app.

+ +

Now you are ready to develop your app. For more information, see the following links:

+ + + + +

Creating an Android Module

+ +

Android application modules contain the src/main/, AndroidManifest.xml, + build.gradle, build output and other files you need to generate your app's APK files. + Android Studio provides a New Module Wizard that you can use to quickly create a new + Android module (or a module from existing code) based on selected application settings, such as + minimum SDK level and activity template.

+ +

To create a new module, select File > New > + Module. Select the desire module type then click Next to enter the basic module + settings:

+ + + +

The wizard creates a new Android application module according to the options you have chosen.

+ + + +

Setting up a Library Module

+ +

A library module is a standard Android module, so you can create a new one in the same way + as you would a new application module, using the New Module wizard and selecting Android + Library as the module type. The created library module will appear in your project view + along with the other modules.

+ +

You can easily change an existing application module to a library module by changing the + plugin assignment in the build.gradle file to com.android.libary.

+ +
+apply plugin: 'com.android.application'
+
+android {...}
+
+ +
+apply plugin: 'com.android.library'
+
+android {...}
+
+ + +

Adding a dependency on a library module

+ +

The library dependency can be declared in the module's manifest file or in the + file.

+ +

A library modules's manifest file must declare all of the shared components that it includes, + just as would a standard Android application. For more information, see the documentation for + AndroidManifest.xml.

+ +

For example, the TicTacToeLib example library + project declares the activity GameActivity:

+
+<manifest>
+  ...
+  <application>
+    ...
+    <activity android:name="GameActivity" />
+    ...
+  </application>
+</manifest>
+
+ + +

To add the dependency declaration to the build file, edit the build file for the app +module (app/build.gradle) and add a dependency on the lib module:

+ +
+...
+dependencies {
+    ...
+    compile project(":lib")
+}
+
+ +

In this example, the lib module can still be built and tested independently, and +the build system creates an AAR package for it that you could reuse in other projects.

+ +

Note: The library settings in the app/build.gradle +file will override any shared library resources declared in the manifest file.

+ + +

Referencing a library module

+ +

If you are developing an application and want to include the shared code or resources from a + library module, you can also do so easily by adding a reference to the library module in the + module's dependency page.

+ +

To add a reference to a library module, follow these steps:

+ +
    +
  1. Make sure that both the module library and the application module that depends on it are + in your proejct. If one of the modules is missing, import it into your project.
  2. + +
  3. In the project view, right-click the dependent module and select + Open > Module Settings.
  4. + +
  5. Right-click the plus icon to add a new dependencies. +

    If you are adding references to multiple libraries, you can set their relative + priority (and merge order) by selecting a library and using the Up and + Down controls. The tools merge the referenced libraries with your application + starting from lowest priority (bottom of the list) to highest (top of the list). If more than one + library defines the same resource ID, the tools select the resource from the library with higher + priority. The application itself has highest priority and its resources are always used in + preference to identical resource IDs defined in libraries.

    +
  6. + +
  7. Use the Scope drop-down to select how the dependency will be applied.
  8. + +
  9. Click Apply to create the dependency and OK to close the + Project Structure window.
  10. +
+ +

Android Studio rebuilds the module, including the contents of the library module the next time + the project or module is built.

+ + + +

Declaring library components in the manifest file

+ +

In the manifest file of the application module, you must add declarations of all components + that the application will use that are imported from a library module. For example, you must + declare any <activity>, <service>, + <receiver>, <provider>, and so on, as well as + <permission>, <uses-library>, and similar elements.

+ +

Declarations should reference the library components by their fully-qualified package names, + where appropriate.

+ +

For example, the TicTacToeMain example + application declares the library activity GameActivity like this:

+
+<manifest>
+  ...
+  <application>
+    ...
+    <activity android:name="com.example.android.tictactoe.library.GameActivity" />
+    ...
+  </application>
+</manifest>
+
+ +

For more information about the manifest file, see the documentation for AndroidManifest.xml.

+ + +

Using the Android Project View

+ + +

The Android project view in Android Studio shows a flattened version of your project's structure +that provides quick access to the key source files of Android projects and helps you work with +the new Gradle-based build system. The +Android project view:

+ + + +
+ +

Figure 9: Show the Android project view.

+
+ + +

Enable and use the Android Project View

+ +

The Android project view is not yet enabled by default. To show the Android project view, +click Project and select Android, as shown in figure 9.

+ +

The Android project view shows all the build files at the top level of the project hierarchy +under Gradle Scripts. Each project module appears as a folder at the top +level of the project hierarchy and contains these three elements at the top level:

+ + + +

Figure 10 shows how the Android project view groups all the instances of the +ic_launcher.png resource for different screen densities under the same element.

+ +

Note: The Android project view shows a hierarchy that helps you +work with Android projects by providing a flattened structure that highlights the most commonly +used files while developing Android applications. However, the project structure on disk differs +from this representation.

+ + +

Figure 10: The traditional project view (left) and the +Android project view (right).

+ + + + diff --git a/docs/html/tools/projects/templates.jd b/docs/html/tools/projects/templates.jd index fce24fd30c892..966d25fc0b158 100644 --- a/docs/html/tools/projects/templates.jd +++ b/docs/html/tools/projects/templates.jd @@ -28,7 +28,7 @@ page.title=Using Code Templates

The SDK tools provide templates for quickly creating Android application projects with the basic - structure or for adding components to your existing projects. The code templates + structure or for adding components to your existing application modules. The code templates provided by the Android SDK follow the Android design and development guidelines to get you on the right track to creating a beautiful, functional application.

@@ -45,30 +45,29 @@ page.title=Using Code Templates

Application Templates

-

Application templates create basic Android applications that you can immediately run and test - on your Android device. These templates are available when you create a new Android project, +

Application templates create basic Android application modules that you can immediately run and test + on your Android device. These templates are available when you create a new Android module, though you can also use these templates to add new activities - to an existing project.

+ to an existing module.

To use Android application templates:

    -
  1. In Eclipse, with the Android Development Tools (ADT) plugin installed, select File - > New > Android.
  2. -
  3. Select Android > Android Application Project, and click - Next.
  4. +
  5. In Android Studio, select File > New > Module.
  6. Enter the settings for your application, including Application Name, - Project Name, Package Name, API level settings and - presentation Theme, and click Next.
  7. -
  8. Enter the project configuration options, and click Next.
  9. -
  10. Optionally enter launcher icon settings, and click Next.
  11. -
  12. In the Create Activity page, select an application template to use. + Company Domain, Package name, and minimum SDK, + then click Next.
  13. +
  14. Select an application template to use, then click Next. For example,
  15. +
  16. Enter the settings for your activity, including Activity Name, + layout Name, Title, and Menu Resource Name, + then click Finish.

@@ -247,7 +246,7 @@ page.title=Using Code Templates

  • Right click the project folder of the Android application where you want to add an activity.
  • Select New > Other...
  • -
  • Select Android > Android Activity, and click Next.
  • +
  • Select Android > Android Activity, then click Next.
  • Select an activity template, then follow the instructions to add it to your existing application.