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