A project in Android Studio contains everything that defines yourworkspace for an app, from source code and assets, to test code and buildconfigurations. When you start a new project, Android Studio creates the necessarystructure for all your files and makes them visible in theProject window on the left side of the IDE (click View> Tool Windows > Project). This page provides an overview of thekey components inside your project.
Modules
A module is a collection of source files and build settings thatallow you to divide your project into discrete units of functionality. Yourproject can have one or many modules and one module may use another module as adependency. Each module can be independently built, tested, and debugged.
I introduced Android Studio's main window at the end of Part 1. This window is divided into several areas, including a Project window where you identify an app's resource files, and various editor windows where you'll write the code and specify resources for mobile apps in Android Studio. The Project window and an editor window are shown in.
Additional modules are often useful when creating code libraries within yourown project or when you want to create different sets of code and resources fordifferent device types, such as phones and wearables, but keep all the filesscoped within the same project and share some code.
You can add a new module to your project by clicking File> New > New Module.
Android Studio offers a few distinct types of module:
In the Create New Module window, Android Studio offers the following types of app modules:
- Phone & Tablet Module
- Wear OS Module
- Android TV Module
- Glass Module
They each provide essential files and some code templates that are appropriate for the corresponding app or device type.
For more information on adding a module, read Add a Module for a New Device.
To learn more, read Add support for Dynamic Delivery.
In the Create New Module window, Android Studio offers the following library modules:
- Android Library: This type of library can contain all file types supported in an Android project, including source code, resources, and manifest files. The build result is an Android Archive (AAR) file that you can add as a dependency for your Android app modules.
- Java Library: This type of library can contain only Java source files. The build result is an Java Archive (JAR) file that you can add as a dependency for your Android app modules or other Java projects.
Using Android Studio to develop your Google Cloud module lets you manage app code and backend code in the same project. You can also run and test your backend code locally, and use Android Studio to deploy your Google Cloud module.
For more information on running and deploying a Google Cloud module, see Running, Testing, and Deploying the Backend.
Some people also refer to modules as sub-projects and that's okay, becauseGradle also refers to modules as projects. For example,when you create a library module and want to add it as a dependency to yourAndroid app module, you must declare it as follows:
Project files
By default, Android Studio displays your project files in theAndroid view. This view does not reflectthe actual file hierarchy on disk, but is organized bymodules and file types to simplify navigation between key source files of your project, hidingcertain files or directories that are not commonly used. Some of the structuralchanges compared to the structure on disk include the following:
- Shows all the project's build-related configuration files in a top-levelGradle Script group.
- Shows all manifest files for each module in a module-level group (when youhave different manifest files for different product flavors and build types).
- Shows all alternative resource files in a single group,instead of in separate folders per resource qualifier. For example, all densityversions of your launcher icon are visible side-by-side.
Within each Android app module, files are shown in the following groups:
- manifests
- Contains the
AndroidManifest.xml
file. - java
- Contains the Java source code files, separated by package names,including JUnit test code.
- res
- Contains all non-code resources, such as XML layouts, UI strings, andbitmap images, divided into corresponding sub-directories. For more informationabout all possible resource types, see Providing Resources.
The Android project view
To see the actualfile structure of the project including all files hidden from theAndroid view, select Project from the dropdownat the top of the Project window.
When you select Project view, you can see a lot more filesand directories. The most important of which are the following:
module-name/
build/
- Contains build outputs.
libs/
- Contains private libraries.
src/
- Contains all code and resource files for the module in the followingsubdirectories:
androidTest/
- Contains code for instrumentation tests that run on an Android device. For more information, see the Android Test documentation.
main/
- Contains the 'main' sourceset files: the Android code and resources shared by all build variants (files for other build variants reside in sibling directories, such as
src/debug/
for the debug build type).AndroidManifest.xml
- Describes the nature of the application and each of its components. For more information, see the AndroidManifest.xml documentation.
java/
- Contains Java code sources.
jni/
- Contains native code using the Java Native Interface (JNI). For more information, see the Android NDK documentation.
gen/
- Contains the Java files generated by Android Studio, such as your
R.java
file and interfaces created from AIDL files. res/
- Contains application resources, such as drawable files, layout files, and UI string. See Application Resources for more information.
assets/
- Contains file that should be compiled into an
.apk
file as-is. 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 theAssetManager
. For example, this is a good location for textures and game data.
test/
- Contains code for local tests that run on your host JVM.
build.gradle
(module)- This defines the module-specific build configurations.
build.gradle
(project)For information about other build files, seeConfigure Your Build.
Project structure settings
To change various settings for your Android Studio project, open theProject Structure dialog by clickingFile > Project Structure. It contains thefollowing sections:
- SDK Location: Sets the location of the JDK, Android SDK, and Android NDK that your project uses.
- Project: Sets the version for Gradle and the Android plugin for Gradle, and the repository location name.
- Developer Services: Contains settings for Android Studio add-in components from Google or other third parties. SeeDeveloper Services, below.
- Modules: Allows you to edit module-specific build configurations, including the target and minimum SDK, the app signature, and library dependencies. See Modules, below.
Developer services
The Developer Services section of the Project Structure dialog box contains configuration pages for several services that you can use with your app. This section contains the following pages:
- Google AdMob: Allows you to turn on Google's Google AdMob component, which helps you understand your users and show them tailored advertisements.
- Analytics: Allows you to turn on Google Analytics, which helps you measure user interactions with your app across various devices and environments.
- Authentication: Allows users to use Google Sign-In to sign in to your app with their Google accounts.
- Cloud: Allows you to turn on Firebase cloud-based services for your app.
- Notifications: Allows you to use Google Cloud Messaging to communicate between your app and your server.
Turning on any of these services may cause Android Studio to add necessary dependencies and permissions to your app. Each configuration page lists these and other actions that Android Studio takes if you enable the associated service.
Modules
The Modules settings section lets you change configuration options for each of your project's modules. Each module's settings page is divided into the following tabs:
- Properties: Specifies the versions of the SDK and build tools to use to compile the module.
- Signing: Specifies the certificate to use to sign your APK.
- Flavors: Lets you create multiple build flavors, where each flavor specifies a set of configuration settings, such as the module's minimum and target SDK version, and the version code and version name. For example, you might define one flavor that has a minimum SDK of 15 and a target SDK of 21, and another flavor that has a minimum SDK of 19 and a target SDK of 23.
- Build Types: Lets you create and modify build configurations, as described in Configuring Gradle Builds. By default, every module has debug and release build types, but you can define more as needed.
- Dependencies: Lists the library, file, and module dependencies for this module. You can add, modify, and delete dependencies from this pane. For more information about module dependencies, see Configuring Gradle Builds.