Android project structure (translation)

Source: Internet
Author: User
Tags configuration settings admob

Original link

Project Overview

An Android Studio project contains all the resources for an application, including the source code, dependent resources, test codes, build configurations, and so on. Create a new project, Android Studio creates all the necessary files and displays them in the "Project" window on the left (click View>tool windows>project). The core components of the project are described below.

Modules

A module is a collection of configuration of the source file and build that allows you to split the project into different functional modules. A project can have one or more module, and one module can rely on another module. Each module can be independent of build, test, Debug.

In addition, the module is often used as a code base for projects, or as a different set of codes for different devices such as mobile phones, watches, and so on. It is important to ensure that all the module (s) are under the same project, and that in addition to the main module, the other module is dependent on the code or resources used in the dependency.

You can click File>new>new module to add a new module to the project.

Android Studio offers a number of different module types:

Android App Module

Provides a container for the application's source code, resource files, and app settings such as module-level build files, Android manifest files, and more. Create a new project, the default module name is "app".

In the Create New Module window, Android Studio provides the following app Module types:

    • Phone & Table module Mobile, pad module
    • Android Wear Module Watch module
    • Android TV Module Television module
    • Glass Module Glasses Module
      Each of the above provides basic file and code templates that are appropriate for the corresponding application or device type.

For more information on adding module, read add a module for a New Device

Library Module

Provides a reusable code container that can be relied upon for other projects or imported from other projects. The library module is the same as an app module structure, but when build, it creates a code archive instead of an apk, so it cannot be installed on the device.

In the "Create New Module" window, Android Studio provides the following library Module:

    • Android Library: This type contains all the file types supported by an Android project, including source code, resource files, manifest files, and so on. The result of build is an archive file (Android Archive file AAR) that can be relied upon as an app module.
    • Java Library: This type contains only Java source files. The result of build is a Java archive file (Java Archive file JAR) that can be relied upon for Android app module or Java project.
Google Cloud Module

This module provides a Google Cloud backend code base. It provides the necessary code and dependencies to connect your app to the Java application engine, Cloud point, and cloud information that simply uses HTTP. You can develop in the background to provide the cloud services your app needs.

Using Android Studio to create a Google Cloud module allows you to manage the backend and app code for the same project. You can also run and test the background code locally.

See more information on adding Google Cloud Module Adding an App Engine Java Servlet module. See more running development for Google Cloud Module View running, testing, and deploying the backend.

Some people have the module as a sub-project, because Gradle can also refer to the module as a project. For example, when you create a library module and use it as a dependency on the app module, you must declare it in the build file:

dependencies {  compile project(‘:my-library-module‘)}
Android Display Type

The default Android studio displays the project file as an "Android" type display. It does not affect the actual file level on the hard disk, but in the form of module and file types, it is simple to show the core files of the project and hide infrequently used files and folders. There are some changes compared to the physical actual file structure:

    • Displays all of the project's build-related configuration files in a top-level Gradle Script Group.
    • The manifest file for each module is presented in a modular grouping (different product build types have different manifest files).
    • Place all the optional resource files in a separate grouping, replacing the modifier for the category folder. For example, the app icon for all of the different pixels can be displayed alongside.

For each Android app module, the files are shown in the following groupings:

Manifests

Contains the Androidmanifest file.

Java

Contains the Java source code files, according to the different package names, package the JUnit test code.

Res

Contains all non-code resources, such as XML layout, the Strings,bitmap picture of the interface, divided by the corresponding subfolder. For more information on resource types, see providing resources.

Project type view for Android

View all files of the project's real file structure, including hidden files under Android View, select project type in the top-level project drop- down box.

When you select Project view, you can see more files and folders. The final one will be as follows:

module-name/    build/ 包含build的输出文件    libs/ 包含私有的库    src/ 包含所有的代码和相应模块下子文件下的所有资源文件        androidTest/包含运行在Android设备上的测试代码。        main/ 包含主要的代码集合:有Android代码和各种build变形共享的资源(其它build的变体文件在统计的目录下,比如src/debug/是调试build类型)            AndroidManifest.xml 描述应用的特性和它的组件。            java/ 包含Java代码。            jni/ 包含用Java Native Interface(JNI)生成的原生代码。            gen/ 包含Android Studio生成的Java文件,例如R.java文件和根据AIDL文件创建的接口等。            res/ 包含应用的资源,比如drawable文件,layout文件,界面的string。            assets/ 包含要被编译在.apk文件的资源文件。你可以用URI和通过AssetManager读取字节流文件的形式来使用这个文件夹下的资源。比如像游戏的数据、texture可以放在改目录下。        test/ 包含运行在JVM上的本地测试代码。    build.gradle(module) 定义了特定的module的build配置。build.gradle(project) 定义了所有module的build的配置。这个文件是项目不可缺少的,所以应该保持该配置与所有源码的一致。
Project Structure Settings

To change the various settings of the Android Studio project, you can click file>project Structure. It contains the following sections:

    • SDKLocation: Set the project's JDK, Android SDK, Android NDK locations.
    • Project: Set the Gradle, Android plugin for gradle version, the name of the library.
    • Developer Services: Contains settings for adding Android Studio add-in components from Google and other third parties.
    • Modules: Allows you to edit the configuration of a specific module, including the target, the minimum version of the SDK, the application's signature, dependent libraries, and so on.
Developer Services

This section contains configuration pages for some of the services that your app uses. Contains the following sections:

    • AdMob: Allows you to open Google's AdMob components to help you understand users and display qualitative ads.
    • Analytics: Allows you to open Google Analytics to help you observe how your app interacts with users on different device environments.
    • Authentication: Allows you to login to the app using Google account.
    • Cloud: Allows you to open firebase cloud infrastructure services for your app.
    • Notifications: Allows you to use Google Cloud information to interact with your apps and services.

Opening any of the services in the app will be an Android studio add the necessary dependencies and permissions. If you want to start a service, each configuration page lists these and other Android studio behavior configurations.

Modules

You can change the configuration of each module in the project in this section. The Settings page for each module contains the following categories:

    • Properties: Specifies the version of the SDK and build tools that compiled the module.
    • Signing: Specify the application's signing certificate
    • Flavors: To create multiple build preferences, each preference specifies the configuration settings for some columns, such as the minimum and target SDK versions of the module, the version name, and the version number. For example: You can set the preference to Minimun Sdk=15,target sdk=21, another preference is minimum sdk=19, target sdk=23.
    • Build Type: The configuration of build can be created and modified. The default each module has a build type of debug and release, but you can define more needed.
    • Dependencies: Lists the class libraries, files, and modules that the module relies on. You can add, modify, and delete dependencies in the change section.
See more resource information
    • Android Test Documents
    • Androidmanifest.xml
    • Android NDK Documents
    • Application Resources
    • https://developer.android.com/reference/android/content/res/AssetManager.html/"title=" Assetmanager "> Assetmanager
    • Configure Your Build
    • Configuring Gradle Builds

Android project structure (translation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.