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
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:
.apk file that you install on a
- device..apk file that gets installed on a device..apk file at build time.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.
-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 Studio project files and settings provide project-wide settings that apply across all + modules in the project.
+ +.ideaappbuildgradle.gitignorebuild.gradlegradle.propertiesgradlewgradlew.batlocal.propertieslocal.properties should not be maintained in a source revision control system. .iml settings.gradleAndroid 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/src/your/package/namespace/ActivityName.java. All other source code
- files (such as .java or .aidl files) go here as well.build/bin/.apk file and other
- compiled resources.jni/gen/R.java file and
- interfaces created from AIDL files.assets/.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/anim/color/drawable/layout/menu/raw/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/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/libs/AndroidManifest.xmlproject.propertiessrc/local.propertiessrc/main/java//ActivityName> .java. All other source
+ code files (such as .java or .aidl files) go here as well.local.properties should not
-be maintained in a source revision control system. If you use Eclipse, this file is not
-used.androidTest/ant.propertiesmain/java/com.>project<.>app<build.xmlmain/jni/main/gen/R.java file and
+ interfaces created from AIDL files.main/assets/.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/anim/color/drawable/layout/menu/raw/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/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/AndroidManifest.xml.gitignore/app.iml/build.gradleproguard-rules.proThe SDK includes an example application called TicTacToeMain that shows how a dependent
- application can use code and resources from an Android Library project. The TicTacToeMain
- application uses code and resources from an example library project called TicTacToeLib.
The SDK includes an example application called TicTacToeMain that shows how a
+ dependent application can use code and resources from an Android Library module. The TicTacToeMain
+ application uses code and resources from an example library module called TicTacToeLib.
To download the sample applications and run them as projects in +
To download the sample applications and run them as modules in your environment, use the Android SDK Manager to download the "Samples for - SDK API 8" (or later) package into your SDK.
+ SDK API 8" (or later) module into your SDK.For more information and to browse the code of the samples, see the TicTacToeMain @@ -218,76 +324,76 @@ used.
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.
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.
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:
Resource conflicts
-Since the tools merge the resources of a library project with those of a dependent application - project, a given resource ID might be defined in both projects. In this case, the tools select +
Since the tools merge the resources of a library module with those of a dependent application + module, a given resource ID might be defined in both modules. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or @@ -297,67 +403,65 @@ used.
Use prefixes to avoid resource conflicts
To avoid resource conflicts for common resource IDs, consider using a prefix or other - consistent naming scheme that is unique to the project (or is unique across all projects).
You cannot export a library project to a JAR file
+You cannot export a library module to a JAR file
-A library cannot be distributed as a binary file (such as a JAR file). This will -be added in a future - version of the SDK Tools.
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a + future version of the SDK Tools.
-A library project can include a JAR library
+A library module can include a JAR library
-You can develop a library project that itself includes a JAR library, however you need to - manually edit the dependent application project's build path and add a path to the JAR file.
You can develop a library module that itself includes a JAR library; however you need to + manually edit the dependent application modules's build path and add a path to the JAR file.
-A library project can depend on an external JAR library
+A library module can depend on an external JAR library
-You can develop a library project that depends on an external library (for example, the Maps +
You can develop a library module that depends on an external library (for example, the Maps
external library). In this case, the dependent application must build against a target that
includes the external library (for example, the Google APIs Add-On). Note also that both the
- library project and the dependent application must declare the external library in their manifest
+ library module and the dependent application must declare the external library in their manifest
files, in a <uses-library>
element.
Library projects cannot include raw assets
+Library modules cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory)
- in a library project. Any asset resources
+ in a library module. Any asset resources
used by an application must be stored in the assets/ directory of the application
- project itself. However, resource files saved in the
- res/ directory are supported.
res/ directory are supported.
- Platform version must be lower than or equal to the Android project
+Platform version must be lower than or equal to the Android module
-A library is compiled as part of the dependent application project, so the API used in the - library project must be compatible with the version of the Android library used to compile the - application project. In general, the library project should use an A library is compiled as part of the dependent application module, so the API used in the + library module must be compatible with the version of the Android library used to compile the + application module. In general, the library module should use an API level that is the same as — or lower - than — that used by the application. If the library project uses an API level that is - higher than that of the application, the application project will not compile. It is + than — that used by the application. If the library module uses an API level that is + higher than that of the application, the application module will not compile. It is perfectly acceptable to have a library that uses the Android 1.5 API (API level 3) and that is - used in an Android 1.6 (API level 4) or Android 2.1 (API level 7) project, for instance.
No restriction on library package names
+No restriction on library module names
There is no requirement for the package name of a library to be the same as that of applications that use it.
Each library project creates its own R class
+Each library module creates its own R class
-When you build the dependent application project, library projects are compiled and
- merged with the application project. Each library has its own R class, named according
+
When you build the dependent application modules, library modules are compiled and
+ merged with the application module. Each library has its own R class, named according
to the library's package name. The R class generated from main
- project and the library project is created in all the packages that are needed including the main
- project's package and the libraries' packages.
Library project storage location
+Library module storage location
-There are no specific requirements on where you should store a library project, relative to a - dependent application project, as long as the application project can reference the library - project by a relative link. What is important is that the main - project can reference the library project through a relative link.
There are no specific requirements on where you should store a library module, relative to a + dependent application module, as long as the application module can reference the library + module by a relative link. What is important is that the main + module can reference the library module through a relative link.
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/
- .java
- file, but can include one.src/productFlavor1/src/testproductFlavor1/gen/src/productFlavor2/src/testproductFlavor2/R.java file and
- interfaces created from AIDL files.assets/res/AndroidManifest.xml<instrumentation>
- element that connects the test project with the application project.project.propertieslocal.propertiesant.propertiesbuild.xmlFor 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.
For more information, see the + Testing section.
+ + +There are two recommended ways of setting up testing on code and resources in a library - project:
+ module: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
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 + +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.
+ + + +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.
+ +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.
+ +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.
+ + +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.
+ + +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.
+ + +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:
+ + + + +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:
+ +minSdkVersion attribute in the build.gradle file.Note: You can manually change the minimum and target SDK + for your module at any time: Double-click the module's build.gradle in the Project Explorer, + set the targetSdkVersion and targetSdkVersion in the + defaultConfig section.
+ + +The wizard creates a new Android application module according to the options you have chosen.
+ + + +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 {...}
+
+
+
+ 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.
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:
+ +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.
+Android Studio rebuilds the module, including the contents of the library module the next time + the project or module is built.
+ + + +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.
+ + +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.
+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:
+ +java/ - Source files for the module.manifests/ - Manifest files for the module.res/ - Resource files for the module.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 TemplatesThe 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 TemplatesApplication 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:
@@ -247,7 +246,7 @@ page.title=Using Code Templates
To use Android object templates: