am 377604af: docs: project updates [CP]
* commit '377604af7f505baf0cb81fe2340b3b4268924988': docs: project updates [CP]
This commit is contained in:
BIN
docs/html/images/tools/studio-androidtest-folder.png
Normal file
BIN
docs/html/images/tools/studio-androidtest-folder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
@@ -1,4 +1,4 @@
|
||||
page.title=Managing Projects
|
||||
page.title=Managing Projects Overview
|
||||
@jd:body
|
||||
|
||||
<div id="qv-wrapper">
|
||||
@@ -6,211 +6,317 @@ page.title=Managing Projects
|
||||
<h2>In this document</h2>
|
||||
|
||||
<ol>
|
||||
<li><a href="#ApplicationProjects">Android Projects</a></li>
|
||||
<li><a href="#ProjectFiles">Android Project Files</a></li>
|
||||
<li><a href="#ApplicationModules">Android Application Modules</a></li>
|
||||
|
||||
<li><a href="#LibraryProjects">Library Projects</a>
|
||||
<li><a href="#LibraryModules">Library Modules</a>
|
||||
<ol>
|
||||
<li><a href="#considerations">Development considerations</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
|
||||
<li><a href="#TestProjects">Test Projects</a></li>
|
||||
<li><a href="#TestModules">Test Modules</a></li>
|
||||
|
||||
<li><a href="#testing">Testing a Library Project</a></li>
|
||||
<li><a href="#testing">Testing a Library Module</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>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 <code>android</code> tool on the command line. There are three types of projects, and
|
||||
they all share the same general structure but differ in function:</p>
|
||||
<p>An Android <em>project</em> 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.</p>
|
||||
|
||||
<p>A <em>module</em> 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:</p>
|
||||
|
||||
<dl>
|
||||
<dt><strong>Android Projects</strong></dt>
|
||||
|
||||
<dd>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 <code>.apk</code> file that you install on a
|
||||
device.</dd>
|
||||
<dt><strong>Android Application Modules</strong></dt>
|
||||
|
||||
<dt><strong>Test Projects</strong></dt>
|
||||
<dd>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 <code>.apk</code> file that gets installed on a device.</dd>
|
||||
|
||||
<dd>These projects contain code to test your application projects and are built into
|
||||
applications that run on a device.</dd>
|
||||
<dt><strong>Test Modules</strong></dt>
|
||||
|
||||
<dt><strong>Library Projects</strong></dt>
|
||||
<dd>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
|
||||
<em>androidTest</em> module for inserting JUnit tests. </dd>
|
||||
|
||||
<dd>These projects contain shareable Android source code and resources that you can reference
|
||||
<dt><strong>Library Modules</strong></dt>
|
||||
|
||||
<dd>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 <code>.apk</code> file at build time.</dd>
|
||||
|
||||
|
||||
<dt><strong>App Engine Modules</strong></dt>
|
||||
|
||||
<dd>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. </dd>
|
||||
|
||||
</dl>
|
||||
|
||||
<p>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
|
||||
<p>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.</p>
|
||||
|
||||
<h2 id="ApplicationProjects">Android Projects</h2>
|
||||
<p class="note"><strong>Note:</strong> Project folders and files apply across the entire Android
|
||||
project and override similar module file settings.</p>
|
||||
|
||||
<p>Android projects are the projects that eventually get built into an <code>.apk</code> 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:</p>
|
||||
|
||||
|
||||
|
||||
<h2 id="ProjectFiles">Android Project Files</h2>
|
||||
|
||||
<p>Android Studio project files and settings provide project-wide settings that apply across all
|
||||
modules in the project. </p>
|
||||
|
||||
<dl>
|
||||
<dt><code>.idea</code></dt>
|
||||
|
||||
<dd>Directory for IntelliJ IDEA settings.</dd>
|
||||
|
||||
|
||||
<dt><code>app</code></dt>
|
||||
|
||||
<dd>Application module directories and files. </dd>
|
||||
|
||||
|
||||
<dt><code>build</code></dt>
|
||||
|
||||
<dd>This directory stories the build output for all project modules.</dd>
|
||||
|
||||
|
||||
<dt><code>gradle</code></dt>
|
||||
|
||||
<dd>Contains the gradler-wrapper files. </dd>
|
||||
|
||||
|
||||
<dt><code>.gitignore</code></dt>
|
||||
|
||||
<dd>Specifies the untracked files that Git should ignore.</dd>
|
||||
|
||||
|
||||
<dt><code>build.gradle</code></dt>
|
||||
|
||||
<dd>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. </dd>
|
||||
|
||||
<dt><code>gradle.properties</code></dt>
|
||||
|
||||
<dd>Project-wide Gradle settings.</dd>
|
||||
|
||||
|
||||
<dt><code>gradlew</code></dt>
|
||||
|
||||
<dd>Gradle startup script for Unix.</dd>
|
||||
|
||||
|
||||
<dt><code>gradlew.bat</code></dt>
|
||||
|
||||
<dd>Gradle startup script for Windows. </dd>
|
||||
|
||||
<dt><code>local.properties</code></dt>
|
||||
|
||||
<dd>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 <code>local.properties</code> should not be maintained in a source revision control system. </dd>
|
||||
|
||||
|
||||
<dt><code><project>.iml</code></dt>
|
||||
|
||||
<dd>Module file created by the IntelliJ IDEA to store module information.</dd>
|
||||
|
||||
<dt><code>settings.gradle</code></dt>
|
||||
|
||||
<dd>Specifies the sub-projects to build.</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
<h2 id="ApplicationModules">Android Application Modules</h2>
|
||||
|
||||
<p>Android Application Modules are the modules that eventually get built into the <code>.apk</code>
|
||||
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:</p>
|
||||
|
||||
<dl>
|
||||
<dt><code>src/</code></dt>
|
||||
|
||||
<dd>Contains your stub Activity file, which is stored at
|
||||
<code>src<em>/your/package/namespace/ActivityName</em>.java</code>. All other source code
|
||||
files (such as <code>.java</code> or <code>.aidl</code> files) go here as well.</dd>
|
||||
<dt><code>build/</code></dt>
|
||||
|
||||
<dt><code>bin/</code></dt>
|
||||
<dd>Contains build folders for the specified build variants. Stored in the main application module.</dd>
|
||||
|
||||
<dd>Output directory of the build. This is where you can find the final <code>.apk</code> file and other
|
||||
compiled resources.</dd>
|
||||
|
||||
<dt><code>jni/</code></dt>
|
||||
|
||||
<dd>Contains native code sources developed using the Android NDK. For more information, see the
|
||||
<a href="{@docRoot}tools/sdk/ndk/index.html">Android NDK documentation</a>.</dd>
|
||||
|
||||
<dt><code>gen/</code></dt>
|
||||
|
||||
<dd>Contains the Java files generated by ADT, such as your <code>R.java</code> file and
|
||||
interfaces created from AIDL files.</dd>
|
||||
|
||||
<dt><code>assets/</code></dt>
|
||||
|
||||
<dd>This is empty. You can use it to store raw asset files. Files that you save here are
|
||||
compiled into an <code>.apk</code> 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.</dd>
|
||||
|
||||
<dt><code>res/</code></dt>
|
||||
|
||||
<dd>
|
||||
Contains application resources, such as drawable files, layout files, and string values. See
|
||||
<a href="{@docRoot}guide/topics/resources/index.html">Application Resources</a> for more
|
||||
information.
|
||||
|
||||
<dl>
|
||||
<dt><code>anim/</code></dt>
|
||||
|
||||
<dd>For XML files that are compiled into animation objects. See the <a href=
|
||||
"{@docRoot}guide/topics/resources/animation-resource.html">Animation</a> resource
|
||||
type.</dd>
|
||||
|
||||
<dt><code>color/</code></dt>
|
||||
|
||||
<dd>For XML files that describe colors. See the <a href=
|
||||
"{@docRoot}guide/topics/resources/color-list-resource.html">Color Values</a> resource
|
||||
type.</dd>
|
||||
|
||||
<dt><code>drawable/</code></dt>
|
||||
|
||||
<dd>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 <a href=
|
||||
"{@docRoot}guide/topics/resources/drawable-resource.html">Drawable</a> resource type.</dd>
|
||||
|
||||
<dt><code>layout/</code></dt>
|
||||
|
||||
<dd>XML files that are compiled into screen layouts (or part of a screen). See the <a href=
|
||||
"{@docRoot}guide/topics/resources/layout-resource.html">Layout</a> resource type.</dd>
|
||||
|
||||
<dt><code>menu/</code></dt>
|
||||
|
||||
<dd>For XML files that define application menus.
|
||||
See the <a href="{@docRoot}guide/topics/resources/menu-resource.html">Menus</a>
|
||||
resource type.</dd>
|
||||
|
||||
<dt><code>raw/</code></dt>
|
||||
|
||||
<dd>For arbitrary raw asset files. Saving asset files here instead of in the
|
||||
<code>assets/</code> 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.</dd>
|
||||
|
||||
<dt><code>values/</code></dt>
|
||||
|
||||
<dd>For XML files that are compiled into many kinds of resource. Unlike other resources in
|
||||
the <code>res/</code> 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.</dd>
|
||||
|
||||
<dt><code>xml/</code></dt>
|
||||
|
||||
<dd>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 <a href=
|
||||
"{@docRoot}reference/android/app/SearchManager.html#SearchabilityMetadata">Searchability
|
||||
Metadata</a>. See <a href="{@docRoot}guide/topics/resources/index.html">Application Resources</a>
|
||||
for more information about configuring these application components.</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><code>libs/</code></dt>
|
||||
|
||||
<dd>Contains private libraries.</dd>
|
||||
<dd>Contains private libraries. Stored in the main application module.</dd>
|
||||
|
||||
<dt><code>AndroidManifest.xml</code></dt>
|
||||
|
||||
<dd>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
|
||||
<a href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>
|
||||
documentation for more information</dd>
|
||||
|
||||
<dt><code>project.properties</code></dt>
|
||||
|
||||
<dd>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
|
||||
<strong>Properties</strong>.</dd>
|
||||
<dt><code>src/</code></dt>
|
||||
|
||||
<dt><code>local.properties</code></dt>
|
||||
<dd>Contains your stub Activity file, which is stored at
|
||||
<code>src<em>/main/java/<namespace.applicationname>/ActivityName></em>.java</code>. All other source
|
||||
code files (such as <code>.java</code> or <code>.aidl</code> files) go here as well.</dd>
|
||||
|
||||
<dd>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 <code>local.properties</code> should not
|
||||
be maintained in a source revision control system. If you use Eclipse, this file is not
|
||||
used.</dd>
|
||||
<dl>
|
||||
<dt><code>androidTest/</code></dt>
|
||||
|
||||
<dt><code>ant.properties</code></dt>
|
||||
<dd>Contains the instrumentation tests. For more information, see the
|
||||
<a href="{@docRoot}tools/testing/index.html">Android Test documentation</a>.</dd>
|
||||
|
||||
<dd>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.</dd>
|
||||
<dt><code>main/java/com.>project<.>app<</code></dt>
|
||||
|
||||
<dt><code>build.xml</code></dt>
|
||||
<dd>Contains Java code source for the app activities.</dd>
|
||||
|
||||
<dt><code>main/jni/</code></dt>
|
||||
|
||||
<dd>Contains native code using the Java Native Interface (JNI). For more information, see the
|
||||
<a href="{@docRoot}tools/sdk/ndk/index.html">Android NDK documentation</a>.</dd>
|
||||
|
||||
<dt><code>main/gen/</code></dt>
|
||||
|
||||
<dd>Contains the Java files generated by Android Studio, such as your <code>R.java</code> file and
|
||||
interfaces created from AIDL files.</dd>
|
||||
|
||||
<dt><code>main/assets/</code></dt>
|
||||
|
||||
<dd>This is empty. You can use it to store raw asset files. Files that you save here are
|
||||
compiled into an <code>.apk</code> 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.</dd>
|
||||
|
||||
<dt><code>main/res/</code></dt>
|
||||
|
||||
<dd>Contains application resources, such as drawable files, layout files, and string values
|
||||
in the following directories. See
|
||||
<a href="{@docRoot}guide/topics/resources/index.html">Application Resources</a> for more
|
||||
information.
|
||||
|
||||
<dl>
|
||||
<dt><code>anim/</code></dt>
|
||||
|
||||
<dd>For XML files that are compiled into animation objects. See the <a href=
|
||||
"{@docRoot}guide/topics/resources/animation-resource.html">Animation</a> resource
|
||||
type.</dd>
|
||||
|
||||
<dt><code>color/</code></dt>
|
||||
|
||||
<dd>For XML files that describe colors. See the <a href=
|
||||
" {@docRoot}guide/topics/resources/color-list-resource.html">Color Values</a> resource
|
||||
type.</dd>
|
||||
|
||||
<dt><code>drawable/</code></dt>
|
||||
|
||||
<dd>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 <a href=
|
||||
"{@docRoot}guide/topics/resources/drawable-resource.html">Drawable</a> resource type.</dd>
|
||||
|
||||
<dt><code>layout/</code></dt>
|
||||
|
||||
<dd>XML files that are compiled into screen layouts (or part of a screen). See the <a href=
|
||||
"{@docRoot}guide/topics/resources/layout-resource.html">Layout</a> resource type.</dd>
|
||||
|
||||
<dt><code>menu/</code></dt>
|
||||
|
||||
<dd>For XML files that define application menus.
|
||||
See the <a href="{@docRoot}guide/topics/resources/menu-resource.html">Menus</a>
|
||||
resource type.</dd>
|
||||
|
||||
<dt><code>raw/</code></dt>
|
||||
|
||||
<dd>For arbitrary raw asset files. Saving asset files here is essentially the same as
|
||||
saving them in the <code>assets/</code> 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.</dd>
|
||||
|
||||
<dt><code>values/</code></dt>
|
||||
|
||||
<dd>For XML files that define resources by XML element type. Unlike other resources in
|
||||
the <code>res/</code> 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.</dd>
|
||||
|
||||
<dt><code>xml/</code></dt>
|
||||
|
||||
<dd>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
|
||||
<a href="{@docRoot}reference/android/app/SearchManager.html#SearchabilityMetadata">
|
||||
Searchability Metadata</a>. See
|
||||
<a href="{@docRoot}guide/topics/resources/index.html">Application Resources</a>
|
||||
for more information about configuring these application components.</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
<dt><code>AndroidManifest.xml</code></dt>
|
||||
|
||||
<dd>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
|
||||
<a href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>
|
||||
documentation for more information</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
<dt><code>.gitignore/</code></dt>
|
||||
|
||||
<dd>Specifies the untracked files ignored by git.</dd>
|
||||
|
||||
<dt><code>app.iml/</code></dt>
|
||||
|
||||
<dd>IntelliJ IDEA module</dd>
|
||||
|
||||
<dt><code>build.gradle</code></dt>
|
||||
|
||||
<dd>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. </dd>
|
||||
|
||||
<dt><code>proguard-rules.pro</code></dt>
|
||||
|
||||
<dd>ProGuard settings file. </dd>
|
||||
|
||||
<dd>The Ant build file for your project. This is only applicable for projects that
|
||||
you build with Ant.</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
<h2 id="LibraryProjects">Library Projects</h2>
|
||||
|
||||
|
||||
<h2 id="LibraryModules">Library Module</h2>
|
||||
|
||||
<div class="sidebox-wrapper">
|
||||
<div class="sidebox">
|
||||
<h2>Library project example code</h2>
|
||||
<h2>Library module example code</h2>
|
||||
|
||||
<p>The SDK includes an example application called <code>TicTacToeMain</code> 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.</p>
|
||||
<p>The SDK includes an example application called <code>TicTacToeMain</code> 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.</p>
|
||||
|
||||
<p>To download the sample applications and run them as projects in
|
||||
<p>To download the sample applications and run them as modules in
|
||||
your environment, use the <em>Android SDK Manager</em> to download the "Samples for
|
||||
SDK API 8" (or later) package into your SDK.</p>
|
||||
SDK API 8" (or later) module into your SDK.</p>
|
||||
|
||||
<p>For more information and to browse the code of the samples, see
|
||||
the <a href="{@docRoot}resources/samples/TicTacToeMain/index.html">TicTacToeMain
|
||||
@@ -218,76 +324,76 @@ used.</dd>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>An Android <em>library project</em> is a development project that holds shared Android
|
||||
source code and resources. Other Android application projects can reference the library project
|
||||
<p>An Android <em>library module</em> 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 <code>.apk</code> files. Multiple
|
||||
application projects can reference the same library project and any single application project
|
||||
can reference multiple library projects.</p>
|
||||
application modules can reference the same library module and any single application module
|
||||
can reference multiple library modules.</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> 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
|
||||
<em>Android SDK Manager</em>, as described in
|
||||
<a href="{@docRoot}sdk/exploring.html">Exploring the SDK</a>.</p>
|
||||
|
||||
<p>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:</p>
|
||||
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:</p>
|
||||
|
||||
<ul>
|
||||
<li>If you are developing multiple related applications that use some of the same components,
|
||||
you move the redundant components out of their respective application projects and create a
|
||||
single, reuseable set of the same components in a library project.</li>
|
||||
you move the redundant components out of their respective application module and create a
|
||||
single, reusable set of the same components in a library module.</li>
|
||||
|
||||
<li>If you are creating an application that exists in both free and paid versions. You move
|
||||
the part of the application that is common to both versions into a library project. The two
|
||||
dependent projects, with their different package names, will reference the library project
|
||||
the part of the application that is common to both versions into a library module. The two
|
||||
dependent modules, with their different package names, will reference the library module
|
||||
and provide only the difference between the two application versions.</li>
|
||||
</ul>
|
||||
|
||||
<p>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 <code>src/</code>,
|
||||
<code>res/</code> 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 <code>R</code> class.</p>
|
||||
<p>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 <code>src/</code>,
|
||||
<code>res/</code> 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 <code>R</code> class.</p>
|
||||
|
||||
<p>However, a library project differs from a standard Android application project in that you
|
||||
<p>However, a library module differs from a standard Android application module in that you
|
||||
cannot compile it directly to its own <code>.apk</code> 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.</p>
|
||||
|
||||
<p>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
|
||||
<p>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 <code>.apk</code>. 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
|
||||
<code>.apk</code>. This gives your application the flexibility to either use or redefine any
|
||||
resource behaviors or values that are defined in any library.</p>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>Once you have added references to library projects to your Android project,
|
||||
<p>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.</p>
|
||||
|
||||
<p>Library projects can reference other library projects and can import an external library
|
||||
(JAR) in the normal way.</p>
|
||||
<p>Library modules can reference other library modules and can import an external library
|
||||
(JAR) in the normal way.</p>
|
||||
|
||||
<h3 id="considerations">Development considerations</h3>
|
||||
|
||||
<p>As you develop your library project and dependent applications, keep the points listed below
|
||||
<p>As you develop your library modules and dependent applications, keep the points listed below
|
||||
in mind:</p>
|
||||
|
||||
<ul>
|
||||
<li><p><strong>Resource conflicts</strong></p>
|
||||
<p>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
|
||||
<p>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.</dd>
|
||||
<li><p><strong>Use prefixes to avoid resource conflicts</strong></p>
|
||||
|
||||
<p>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).</p></li>
|
||||
consistent naming scheme that is unique to the module (or is unique across all project modules).</p></li>
|
||||
|
||||
<li><p><strong>You cannot export a library project to a JAR file</strong></p>
|
||||
<li><p><strong>You cannot export a library module to a JAR file</strong></p>
|
||||
|
||||
<p>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.</p></li>
|
||||
<p>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.</p></li>
|
||||
|
||||
<li><p><strong>A library project can include a JAR library</strong></p>
|
||||
<li><p><strong>A library module can include a JAR library</strong></p>
|
||||
|
||||
<p>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.</p></li>
|
||||
<p>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.</p></li>
|
||||
|
||||
<li><p><strong>A library project can depend on an external JAR library</strong></p>
|
||||
<li><p><strong>A library module can depend on an external JAR library</strong></p>
|
||||
|
||||
<p>You can develop a library project that depends on an external library (for example, the Maps
|
||||
<p>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 <a href=
|
||||
"{@docRoot}guide/topics/manifest/uses-library-element.html"><code><uses-library></code></a>
|
||||
element.</p></li>
|
||||
|
||||
<li> <p><strong>Library projects cannot include raw assets</strong></p>
|
||||
<li> <p><strong>Library modules cannot include raw assets</strong></p>
|
||||
|
||||
<p>The tools do not support the use of raw asset files (saved in the <code>assets/</code> directory)
|
||||
in a library project. Any asset resources
|
||||
in a library module. Any asset resources
|
||||
used by an application must be stored in the <code>assets/</code> directory of the application
|
||||
project itself. However, resource files saved in the
|
||||
<code>res/</code> directory are supported.</p></li>
|
||||
module itself. However, resource files saved in the <code>res/</code> directory are supported.</p></li>
|
||||
|
||||
<li><p><strong>Platform version must be lower than or equal to the Android project</strong></p>
|
||||
<li><p><strong>Platform version must be lower than or equal to the Android module</strong></p>
|
||||
|
||||
<p>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 href=
|
||||
<p>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 <a href=
|
||||
"{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">API level</a> 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.</p></li>
|
||||
used in an Android 1.6 (API level 4) or Android 2.1 (API level 7) module, for instance.</p></li>
|
||||
|
||||
<li> <p><strong>No restriction on library package names</strong></p>
|
||||
<li> <p><strong>No restriction on library module names</strong></p>
|
||||
|
||||
<p>There is no requirement for the package name of a library to be the same as that of
|
||||
applications that use it.</p></li>
|
||||
|
||||
<li><p><strong>Each library project creates its own R class </strong></p>
|
||||
<li><p><strong>Each library module creates its own R class </strong></p>
|
||||
|
||||
<p>When you build the dependent application project, library projects are compiled and
|
||||
merged with the application project. Each library has its own <code>R</code> class, named according
|
||||
<p>When you build the dependent application modules, library modules are compiled and
|
||||
merged with the application module. Each library has its own <code>R</code> class, named according
|
||||
to the library's package name. The <code>R</code> 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.</p></li>
|
||||
module and the library module is created in all the packages that are needed including the main
|
||||
module's package and the libraries' packages.</p></li>
|
||||
|
||||
<li><p><strong>Library project storage location</strong></p>
|
||||
<li><p><strong>Library module storage location</strong></p>
|
||||
|
||||
<p>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.</p></li>
|
||||
<p>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.</p></li>
|
||||
</ul>
|
||||
|
||||
<h2 id="TestProjects">Test Projects</h2>
|
||||
@@ -365,82 +469,55 @@ be added in a future
|
||||
<p>Test projects contain Android applications that you write using the
|
||||
<a href="{@docRoot}tools/testing/index.html">Testing and
|
||||
Instrumentation framework</a>. 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.</p>
|
||||
access to Android system objects. </p>
|
||||
|
||||
<p>The test projects are now automatically part of the app source folder. When a new application
|
||||
module is created, Android Studio creates the <code>src/androidTest</code> source set. This
|
||||
source set contains tests for the default configuration and is combined with the <em>debug</em>
|
||||
build type to generate a test application. </p>
|
||||
|
||||
<img src="{@docRoot}images/tools/studio-androidtest-folder.png">
|
||||
<p class="img-caption"><strong>Figure 1.</strong> androidTest Folder.</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> The <code>src/androidTest</code> 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.</p>
|
||||
|
||||
<p>For each product flavor, create a test folder specific to that product flavor. </p>
|
||||
|
||||
<dl>
|
||||
<dt><code>src/</code></dt>
|
||||
<dt><code>src/main/</code></dt>
|
||||
<dd><code>src/androidTest/</code></dt>
|
||||
|
||||
<dd>Includes your test source files. Test projects do not require an Activity <code>.java</code>
|
||||
file, but can include one.</dd>
|
||||
<dt><code>src/productFlavor1/</code></dt>
|
||||
<dd><code>src/testproductFlavor1/</code></dd>
|
||||
|
||||
<dt><code>gen/</code></dt>
|
||||
<dt><code>src/productFlavor2/</code></dt>
|
||||
<dd><code>src/testproductFlavor2/</code></dd>
|
||||
|
||||
<dd>This contains the Java files generated by ADT, such as your <code>R.java</code> file and
|
||||
interfaces created from AIDL files.</dd>
|
||||
|
||||
<dt><code>assets/</code></dt>
|
||||
|
||||
<dd>This is empty. You can use it to store raw asset files.</dd>
|
||||
|
||||
<dt><code>res/</code></dt>
|
||||
|
||||
<dd>A folder for your application resources, such as drawable files, layout files, string
|
||||
values, etc. See <a href="{@docRoot}guide/topics/resources/index.html">Application
|
||||
Resources</a>.</dd>
|
||||
|
||||
<dt><code>AndroidManifest.xml</code></dt>
|
||||
|
||||
<dd>The Android Manifest for your project. See <a href=
|
||||
"{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a>. Test
|
||||
Projects have a special <a href=
|
||||
"{@docRoot}guide/topics/manifest/instrumentation-element.html">
|
||||
<code><instrumentation></code></a>
|
||||
element that connects the test project with the application project.</dd>
|
||||
|
||||
<dt><code>project.properties</code></dt>
|
||||
|
||||
<dd>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 <strong>Properties</strong>.</dd>
|
||||
|
||||
<dt><code>local.properties</code></dt>
|
||||
|
||||
<dd>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.</dd>
|
||||
|
||||
<dt><code>ant.properties</code></dt>
|
||||
|
||||
<dd>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.</dd>
|
||||
|
||||
<dt><code>build.xml</code></dt>
|
||||
|
||||
<dd>The Ant build file for your project. This is only applicable for projects that
|
||||
you build with Ant.</dd>
|
||||
</dl>
|
||||
|
||||
<p>For more information, see the <a href=
|
||||
"{@docRoot}tools/testing/index.html">Testing</a> section.</p>
|
||||
<p>The test manifests are always generated so a manifest in a test source set is optional.</p>
|
||||
|
||||
<p>The test applications run against the <em>debug</em> build type. This can be configured
|
||||
using the <code>testBuildType</code> property in the build file.</p>
|
||||
|
||||
|
||||
<h2 id="testing">Testing a Library Project</h2>
|
||||
<p>For more information, see the
|
||||
<a href="{@docRoot}tools/testing/index.html">Testing</a> section.</p>
|
||||
|
||||
|
||||
<h2 id="testing">Testing a Library Module</h2>
|
||||
|
||||
<p>There are two recommended ways of setting up testing on code and resources in a library
|
||||
project:</p>
|
||||
module:</p>
|
||||
|
||||
<ul>
|
||||
<li>You can set up a <a href="{@docRoot}tools/testing/testing_otheride.html">test
|
||||
project</a> that instruments an application project that depends on the library project. You
|
||||
can then add tests to the project for library-specific features.</li>
|
||||
module</a> that instruments an application module that depends on the library module. You
|
||||
can then add tests to the module for library-specific features.</li>
|
||||
|
||||
<li>You can set up a standard application project that depends on the library and put
|
||||
the instrumentation in that project. This lets you create a self-contained project that
|
||||
<li>You can set up a standard application module that depends on the library and put
|
||||
the instrumentation in that module. This lets you create a self-contained module that
|
||||
contains both the tests/instrumentations and the code to test.</li>
|
||||
</ul>
|
||||
|
||||
@@ -118,7 +118,7 @@ android create project \
|
||||
|
||||
<h2 id="UpdatingAProject">Updating a Project</h2>
|
||||
|
||||
<p>If you're upgrading a project from an older version of the Android SDK or want to create a new
|
||||
<p>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 <code>android update project</code> 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 <code>--target</code> option) and the project name (with
|
||||
@@ -288,7 +288,7 @@ android.library.reference.1=path/to/library_projectC
|
||||
<h3 id="depAppBuild">Building a dependent application</h3>
|
||||
|
||||
<p>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 <a href=
|
||||
standard Gradle build commands and compile modes, as described in <a href=
|
||||
"{@docRoot}tools/building/index.html">Building and Running</a>. 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.</p>
|
||||
|
||||
398
docs/html/tools/projects/projects-studio.jd
Normal file
398
docs/html/tools/projects/projects-studio.jd
Normal file
@@ -0,0 +1,398 @@
|
||||
page.title=Managing Projects from Android Studio
|
||||
|
||||
@jd:body
|
||||
|
||||
<div id="qv-wrapper">
|
||||
<div id="qv">
|
||||
<h2>In this document</h2>
|
||||
|
||||
<ol>
|
||||
<li><a href="#CreatingAProject">Creating an Android Project</a></li>
|
||||
<ol>
|
||||
<li><a href="#Step1CreatingAProject">Create a New Project</a> </li>
|
||||
<li><a href="#Step2SelectFormFactor">Select Form Factors and API Level</a> </li>
|
||||
<li><a href="#Step3AddActivity">Add an Activity</a> </li>
|
||||
<li><a href="#Step4ConfigureActivity">Configure Your App</a> </li>
|
||||
<li><a href="#Step5DevelopYourApp">Develop Your App</a> </li>
|
||||
</ol>
|
||||
|
||||
<li><a href="#CreatingAModule">Creating an Android Module</a></li>
|
||||
|
||||
<li><a href="#SettingUpLibraryModule">Setting up a Library Module</a></li>
|
||||
|
||||
<li><a href="#ReferencingLibraryModule">Referencing a Library Module</a></li>
|
||||
|
||||
<li><a href="#ReferencingAppEngModule">Setting up an App Eng Module</a></li>
|
||||
|
||||
<li><a href="#ProjectView">Using the Android Project View</a></li>
|
||||
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>This guide explains how to create Android projects and different modules using
|
||||
<a href="{@docRoot}tools/studio/index.html">Android Studio</a>.
|
||||
For more information about the Android project structure and module types, read <a href=
|
||||
"{@docRoot}tools/projects/index.html">Managing Projects Overview</a>.</p>
|
||||
|
||||
|
||||
|
||||
<h2 id="CreatingAProject">Creating an Android Project</h2>
|
||||
|
||||
<p>Android Studio makes it easy to create Android apps for several form factors, such as phone,
|
||||
tablet, TV, Wear, and Google Glass. The <em>New Project</em> wizard lets you choose the form factors
|
||||
for your app and populates the project structure with everything you need to get started.</p>
|
||||
|
||||
<p>Follow the steps in this section to create a project in Android Studio.</p>
|
||||
|
||||
<h3 id="Step1CreatingAProject">Step 1: Create a New Project</h2>
|
||||
|
||||
<p>If you didn't have a project opened, Android Studio shows the Welcome screen.
|
||||
To create a new project, click <strong>New Project</strong>.</p>
|
||||
|
||||
<p>If you had a project opened, Android Studio shows the development environment.
|
||||
To create a new project, click <strong>File</strong> > <strong>New Project</strong>.</p>
|
||||
|
||||
<p>The next window lets you configure the name of your app, the package name, and the location
|
||||
of your project.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard2.png" alt="" width="500" height="381">
|
||||
<p class="img-caption"><strong>Figure 1.</strong> Choose a name for your project.</p>
|
||||
|
||||
<p>Enter the values for your project then click <strong>Next</strong>.</p>
|
||||
|
||||
<h3 id="Step2SelectFormFactor">Step 2: Select Form Factors and API Level</h2>
|
||||
|
||||
<p>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 <strong>Help me choose</strong>.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard4.png" alt="" width="750" height="510">
|
||||
<p class="img-caption"><strong>Figure 2.</strong> Select the API Level.</p>
|
||||
|
||||
<p>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 <strong>OK</strong>.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard3.png" alt="" width="500" height="480">
|
||||
<p class="img-caption"><strong>Figure 3.</strong> Choose form factors for your app.</p>
|
||||
|
||||
<p>Then, on the Form Factors Window, click <strong>Next</strong>.</p>
|
||||
|
||||
|
||||
<h3 id="Step3AddActivity">Step 3: Add an Activity</h2>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard5.png" alt="" width="720" height="504">
|
||||
<p class="img-caption"><strong>Figure 4.</strong> Add an activity to your app.</p>
|
||||
|
||||
<p>Choose an activity type then click <strong>Next</strong>.</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> If you choose "Add No Activity", click <strong>Finish</strong>
|
||||
to create the project.</p>
|
||||
|
||||
|
||||
<h3 id="Step4ConfigureActivity">Step 4: Configure Your Activity</h2>
|
||||
|
||||
<p>The next screen lets you configure the activity to add to your app, as shown in figure 5.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard6.png" alt="" width="450" height="385">
|
||||
<p class="img-caption"><strong>Figure 5.</strong> Choose a name for your activity.</p>
|
||||
|
||||
<p>Enter the activity name, the layout name, and the activity title. Then click
|
||||
<strong>Finish</strong>.</p>
|
||||
|
||||
|
||||
<h3 id="Step5DevelopYourApp">Step 5: Develop Your App</h2>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/wizard7.png" alt="" width="750" height="509">
|
||||
<p class="img-caption"><strong>Figure 6.</strong> The default project structure for a mobile app.</p>
|
||||
|
||||
<p>Now you are ready to develop your app. For more information, see the following links:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="{@docRoot}training/">Training Lessons</a></li>
|
||||
<li><a href="{@docRoot}training/building-wearables.html">Building Apps for Wearables</a></li>
|
||||
<li><a href="{@docRoot}tv/">Android TV</a></li>
|
||||
<li><a href="https://developers.google.com/glass/">Google Glass</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2 id="CreatingAModule">Creating an Android Module</h2>
|
||||
|
||||
<p>Android application modules contain the <code>src/main/</code>, <code>AndroidManifest.xml</code>,
|
||||
<code>build.gradle</code>, build output and other files you need to generate your app's APK files.
|
||||
Android Studio provides a <em>New Module Wizard</em> 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.</p>
|
||||
|
||||
<p>To create a new module, select <strong>File</strong> > <strong>New</strong> >
|
||||
<strong>Module</strong>. Select the desire module type then click Next to enter the basic module
|
||||
settings:</p>
|
||||
|
||||
<ul>
|
||||
<li>Enter an <strong>Application Name</strong>. This name is used as the title of your
|
||||
application launcher icon when it is installed on a device.</li>
|
||||
|
||||
<li>Enter a <strong>Module Name</strong>. This text is used as the name of the folder where
|
||||
your Java-based activity files are stored.</li>
|
||||
|
||||
<li>Enter a <strong>Package Name</strong> and <strong>Package Location</strong>. This class
|
||||
package namespace creates the initial
|
||||
package structure for your applications code files and is added as the
|
||||
<a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">{@code package}</a>
|
||||
attribute in your application's
|
||||
<a href="{@docRoot}guide/topics/manifest/manifest-intro.html">Android manifest file</a>.
|
||||
This manifest value serves as the unique identifier for your application app when you
|
||||
distribute it to users. The package name must follow the same rules as packages in the Java
|
||||
programming language.</li>
|
||||
|
||||
<li>Select the <strong>Minimum required SDK</strong>.
|
||||
This setting indicates the lowest version of the Android platform that your application
|
||||
supports for the selected form factor. This value sets the
|
||||
<code>minSdkVersion</code> attribute in the build.gradle file.</li>
|
||||
|
||||
<p class="note"><strong>Note:</strong> 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 <strong>targetSdkVersion</strong> and <em>targetSdkVersion</em> in the
|
||||
<em>defaultConfig</em> section.</p>
|
||||
|
||||
|
||||
<li>Select a <strong>Target SDK</strong>. This setting indicates the highest version of
|
||||
Android with which you have tested with your application and sets the
|
||||
<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
|
||||
targetSdkVersion}</a> attribute in your application's' build.gradle file.
|
||||
|
||||
|
||||
<li>Select a <strong>Compile With</strong> API version. This setting specifies what version
|
||||
of the SDK to compile your project against. We strongly recommend using the most recent
|
||||
version of the API.</li>
|
||||
|
||||
<li>Select a <strong>Language Level</strong> API version. This setting specifies what version
|
||||
of the SDK to compile your project against. We strongly recommend using the most recent
|
||||
version of the API.</li>
|
||||
|
||||
<li>Select a <strong>Theme</strong>. This setting specifies which standard Android
|
||||
<a href="{@docRoot}design/style/themes.html">visual style</a> is applied to your
|
||||
application. Select activity template. For more information about Android code templates, see
|
||||
<a href="{@docRoot}tools/projects/templates.html">Using Code Templates</a>Leave the <strong>
|
||||
Create activity</strong> option checked so you can start your
|
||||
application with some essential components. </li>
|
||||
|
||||
<li>Click the check box for the required Support Libraries then click <strong>Next</strong>.</li>
|
||||
|
||||
<li>In the <strong>Configure Launcher Icon</strong> page, create an icon and options, then click
|
||||
<strong>Next</strong>.</li>
|
||||
|
||||
<li>In the <strong>Create Activity</strong> page, select activity template then click
|
||||
<strong>Next</strong>. For more information about Android code templates, see
|
||||
<a href="{@docRoot}tools/projects/templates.html">Using Code Templates</a>.
|
||||
</li>
|
||||
|
||||
<li>Review the new module settings then click <strong>Finish</strong>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>The wizard creates a new Android application module according to the options you have chosen.</p>
|
||||
|
||||
|
||||
|
||||
<h2 id="SettingUpLibraryModule">Setting up a Library Module</h2>
|
||||
|
||||
<p>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 <em>Android
|
||||
Library</em> as the module type. The created library module will appear in your project view
|
||||
along with the other modules. </p>
|
||||
|
||||
<p> You can easily change an existing application module to a library module by changing the
|
||||
plugin assignment in the <strong>build.gradle</strong> file to <em>com.android.libary</em>.</p>
|
||||
|
||||
<pre>
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {...}
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {...}
|
||||
</pre>
|
||||
|
||||
|
||||
<h3>Adding a dependency on a library module</h3>
|
||||
|
||||
<p>The library dependency can be declared in the module's manifest file or in the
|
||||
<strong<build.gradle</strong> file. </p>
|
||||
|
||||
<p>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
|
||||
<a href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
|
||||
|
||||
<p>For example, the <a href=
|
||||
"{@docRoot}resources/samples/TicTacToeLib/AndroidManifest.html">TicTacToeLib</a> example library
|
||||
project declares the activity <code>GameActivity</code>:</p>
|
||||
<pre>
|
||||
<manifest>
|
||||
...
|
||||
<application>
|
||||
...
|
||||
<activity android:name="GameActivity" />
|
||||
...
|
||||
</application>
|
||||
</manifest>
|
||||
</pre>
|
||||
|
||||
|
||||
<p>To add the dependency declaration to the build file, edit the build file for the <code>app</code>
|
||||
module (<code>app/build.gradle</code>) and add a dependency on the <code>lib</code> module:</p>
|
||||
|
||||
<pre>
|
||||
...
|
||||
dependencies {
|
||||
...
|
||||
compile project(":lib")
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>In this example, the <code>lib</code> 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.</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> The library settings in the <code>app/build.gradle</code>
|
||||
file will override any shared library resources declared in the manifest file.</p>
|
||||
|
||||
|
||||
<h2 id="ReferencingLibraryModule">Referencing a library module</h2>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>To add a reference to a library module, follow these steps:</p>
|
||||
|
||||
<ol>
|
||||
<li>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.</li>
|
||||
|
||||
<li>In the project view, right-click the dependent module and select
|
||||
<strong>Open</strong> > <strong>Module Settings</strong>.</li>
|
||||
|
||||
<li>Right-click the plus icon to add a new dependencies.
|
||||
<p>If you are adding references to multiple libraries, you can set their relative
|
||||
priority (and merge order) by selecting a library and using the <strong>Up</strong> and
|
||||
<strong>Down</strong> 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.</p>
|
||||
</li>
|
||||
|
||||
<li>Use the <strong>Scope</strong> drop-down to select how the dependency will be applied.</li>
|
||||
|
||||
<li>Click <strong>Apply</strong> to create the dependency and <strong>OK</strong> to close the
|
||||
<strong>Project Structure</strong> window.</li>
|
||||
</ol>
|
||||
|
||||
<p>Android Studio rebuilds the module, including the contents of the library module the next time
|
||||
the project or module is built.</p>
|
||||
|
||||
|
||||
|
||||
<h3>Declaring library components in the manifest file</h3>
|
||||
|
||||
<p>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 <code><activity></code>, <code><service></code>,
|
||||
<code><receiver></code>, <code><provider></code>, and so on, as well as
|
||||
<code><permission></code>, <code><uses-library></code>, and similar elements.</p>
|
||||
|
||||
<p>Declarations should reference the library components by their fully-qualified package names,
|
||||
where appropriate.</p>
|
||||
|
||||
<p>For example, the <a href=
|
||||
"{@docRoot}resources/samples/TicTacToeMain/AndroidManifest.html">TicTacToeMain</a> example
|
||||
application declares the library activity <code>GameActivity</code> like this:</p>
|
||||
<pre>
|
||||
<manifest>
|
||||
...
|
||||
<application>
|
||||
...
|
||||
<activity android:name="com.example.android.tictactoe.library.GameActivity" />
|
||||
...
|
||||
</application>
|
||||
</manifest>
|
||||
</pre>
|
||||
|
||||
<p>For more information about the manifest file, see the documentation for <a href=
|
||||
"{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
|
||||
|
||||
|
||||
<h2 id="ProjectView">Using the Android Project View</h2>
|
||||
|
||||
|
||||
<p>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 <a href="{@docRoot}sdk/installing/studio-build.html">Gradle-based build system</a>. The
|
||||
Android project view:</p>
|
||||
|
||||
<ul>
|
||||
<li>Groups the build files for all modules at the top level of the project hierarchy.</li>
|
||||
<li>Shows the most important source directories at the top level of the module hierarchy.</li>
|
||||
<li>Groups all the manifest files for each module.</li>
|
||||
<li>Shows resource files from all Gradle source sets.</li>
|
||||
<li>Groups resource files for different locales, orientations, and screen types in a single group
|
||||
per resource type.</li>
|
||||
</ul>
|
||||
|
||||
<div style="float:right;margin-left:30px;width:240px">
|
||||
<img src="{@docRoot}images/tools/projectview01.png" alt="" width="220" height="264"/>
|
||||
<p class="img-caption"><strong>Figure 9:</strong> Show the Android project view.</p>
|
||||
</div>
|
||||
|
||||
|
||||
<h2 id="enable-view">Enable and use the Android Project View</h2>
|
||||
|
||||
<p>The Android project view is not yet enabled by default. To show the Android project view,
|
||||
click <strong>Project</strong> and select <strong>Android</strong>, as shown in figure 9.</p>
|
||||
|
||||
<p>The Android project view shows all the build files at the top level of the project hierarchy
|
||||
under <strong>Gradle Scripts</strong>. Each project module appears as a folder at the top
|
||||
level of the project hierarchy and contains these three elements at the top level:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>java/</code> - Source files for the module.</li>
|
||||
<li><code>manifests/</code> - Manifest files for the module.</li>
|
||||
<li><code>res/</code> - Resource files for the module.</li>
|
||||
</ul>
|
||||
|
||||
<p>Figure 10 shows how the Android project view groups all the instances of the
|
||||
<code>ic_launcher.png</code> resource for different screen densities under the same element.</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> 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.</p>
|
||||
|
||||
<img src="{@docRoot}images/tools/projectview03.png" alt=""
|
||||
style="margin-top:10px" width="650" height="508"/>
|
||||
<p class="img-caption"><strong>Figure 10:</strong> The traditional project view (left) and the
|
||||
Android project view (right).</p>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ page.title=Using Code Templates
|
||||
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
@@ -45,30 +45,29 @@ page.title=Using Code Templates
|
||||
|
||||
<h2 id="app-templates">Application Templates</h2>
|
||||
|
||||
<p>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,
|
||||
<p>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 <a href="#activity-templates">add new activities</a>
|
||||
to an existing project.</p>
|
||||
to an existing module.</p>
|
||||
|
||||
<p>To use Android application templates:</p>
|
||||
|
||||
<ol>
|
||||
<li>In Eclipse, with the Android Development Tools (ADT) plugin installed, select <strong>File
|
||||
> New > Android</strong>.</li>
|
||||
<li>Select <strong>Android > Android Application Project</strong>, and click
|
||||
<strong>Next</strong>.</li>
|
||||
<li>In Android Studio, select <strong>File > New > Module</strong>.</li>
|
||||
<li>Enter the settings for your application, including <strong>Application Name</strong>,
|
||||
<strong>Project Name</strong>, <strong>Package Name</strong>, API level settings and
|
||||
presentation <strong>Theme</strong>, and click <strong>Next</strong>.</li>
|
||||
<li>Enter the project configuration options, and click <strong>Next</strong>.</li>
|
||||
<li>Optionally enter launcher icon settings, and click <strong>Next</strong>.</li>
|
||||
<li>In the <strong>Create Activity</strong> page, select an application template to use.
|
||||
<strong>Company Domain</strong>, <strong>Package name</strong>, and <strong>minimum SDK</strong>,
|
||||
then click <strong>Next</strong>.</li>
|
||||
<li>Select an application template to use, then click <strong>Next</strong>. For example,
|
||||
<ul>
|
||||
<li><a href="#blank-activity">BlankActivity</a></li>
|
||||
<li><a href="#full-screen-activity">FullScreenActivity</a></li>
|
||||
<li><a href="#master-detail-activity">MasterDetailFlow</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<li>Enter the settings for your activity, including <strong>Activity Name</strong>,
|
||||
<strong>layout Name</strong>, <strong>Title</strong>, and <strong>Menu Resource Name</strong>,
|
||||
then click <strong>Finish</strong>.</li>
|
||||
</ol>
|
||||
|
||||
<p class="note">
|
||||
@@ -247,7 +246,7 @@ page.title=Using Code Templates
|
||||
<li>Right click the project folder of the Android application where you want to add an
|
||||
activity.</li>
|
||||
<li>Select <strong>New > Other...</strong></li>
|
||||
<li>Select <strong>Android > Android Activity</strong>, and click <strong>Next</strong>.</li>
|
||||
<li>Select <strong>Android > Android Activity</strong>, then click <strong>Next</strong>.</li>
|
||||
<li>Select an activity template, then follow the instructions to add it to your existing
|
||||
application.
|
||||
<ul>
|
||||
@@ -331,17 +330,23 @@ including the previously mentioned activities as well as the following additiona
|
||||
<p>To use Android object templates:</p>
|
||||
|
||||
<ol>
|
||||
<li>Right click the project folder of the Android application where you want to add a code
|
||||
<li>Right-click the module folder of the Android application where you want to add a code
|
||||
component.</li>
|
||||
<li>Select <strong>New > Other...</strong></li>
|
||||
<li>Select <strong>Android > Android Object</strong>, and click <strong>Next</strong>.</li>
|
||||
<li>Select an object template, then follow the instructions to add it to your existing
|
||||
<li>Select <strong>New</strong></li>
|
||||
<li>Select the object type and template, then follow the instructions to add it to your existing
|
||||
application.
|
||||
<ul>
|
||||
<li>{@link android.content.BroadcastReceiver}</li>
|
||||
<li>{@link android.content.ContentProvider}</li>
|
||||
<li><a href="{@docRoot}guide/topics/ui/custom-components.html">Custom View</a></li>
|
||||
<li>{@link android.app.Service}</li>
|
||||
<li>AIDL</li>
|
||||
<li>Activity</li>
|
||||
<li>Folder</li>
|
||||
<li>Fragment</li>
|
||||
<li>Google</li>
|
||||
<li>Other</li>
|
||||
<li>Service</li>
|
||||
<li>UI Component</li>
|
||||
<li>Wear</li>
|
||||
<li>Widget</li>
|
||||
<li>XML</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-section">
|
||||
<div class="nav-section-header"><a href="<?cs var:toroot ?>tools/projects/index.html"><span class="en">Setting Up Projects</span></a></div>
|
||||
<div class="nav-section-header"><a href="<?cs var:toroot ?>tools/projects/index.html"><span class="en">Managing Projects</span></a></div>
|
||||
<ul>
|
||||
<li><a href="<?cs var:toroot ?>tools/projects/projects-eclipse.html"><span class="en">From Eclipse with ADT</span></a></li>
|
||||
<li><a href="<?cs var:toroot ?>tools/projects/projects-cmdline.html"><span class="en">From the Command Line</span></a></li>
|
||||
|
||||
Reference in New Issue
Block a user