Android Studio project directory structure analysis (1)

Android Studio project directory


Here we analyze it with a simple HelloWorld project:


    1. The two directories , .gradle and .idea , are all files automatically generated by Android Studio. We don't need to care about them or edit them manually.
    
2、app
         Almost all the code, resources and other content in the project are placed in this directory, and our subsequent development work is basically carried out in this directory, and this directory will be explained separately later.
3、build
         You don't need to care too much about this directory, it mainly contains some files that are automatically generated at compile time.
4、gradle
         This directory contains the configuration files of gradle wrapper. The way of using gradle wrapper does not need to download gradle in advance, but will automatically decide whether to download gradle online according to the local cache situation. Android Studio does not start the gradle wrapper by default. If you need to open it, you can click the Android Studio navigation bar --> File --> Settings --> Build, Execution, Deployment --> Gradle to make configuration changes.
5 、 .gitignore
         This file is used to exclude the specified directory or file from version control.
6、build.gradle
         This is the project's global gradle build script. Usually, the contents of this file do not need to be modified. The specific content in the gradle build script will be analyzed in detail below.
7、gradle.properties
         This file is the global gradle configuration file, the properties configured here will affect all gradle compilation scripts in the project.
8、gradlew和gradlew.bat
         These two files are used to execute gradle commands in the command line interface, where gradlew is used in Linux or Mac systems, and gradlew.bat is used in Windows systems.
9、HelloWorld.iml
         The iml file is a file automatically generated by all IntelliJ IDEA projects (Android Studio is developed based on IntelliJ IDEA ), which is used to identify that this is an IntelliJ IDEA project, and we do not need to modify anything in this file.
10、local.properties
         This file is used to specify the Android SDK path in the machine. Usually the content is automatically generated and we do not need to modify it. Unless the location of the Android SDK in your local machine has changed, just change the path in this file to the new location.
11、settings.gradle
         This file is used to specify all imported modules in the project. Since there is only one app module in the HelloWorld project, only the app module is introduced in this file. Usually, the introduction of modules is done automatically, and there may be fewer scenarios that require us to manually modify this file.

app directory structure


         Now the outer directory structure of the entire project has been introduced. You will find that, except for the app directory, most of the files and directories are automatically generated and we do not need to modify them. As you must have guessed, the content in the app directory is the focus of our future work. After expansion, the structure is as follows:


         Then let's analyze the contents of the app directory in more detail.
1、build
         This directory is similar to the outer build directory. It mainly contains some files that are automatically generated at compile time, but the content in it will be more and more complicated, and we don't need too much relationship.
2、libs
         If you use third-party jar packages in your project, you need to put these jar packages in the libs directory, and the jar packages in this directory will be automatically added to the build path.
3 、 AndroidTest
         This is used to write Android Test test cases, you can perform some automated tests on the project.
4、java
         There is no doubt that the java directory is where all our java code will be placed, expand that directory and you will see the HelloWorldActivity file we just created is there.
5、res
         这个目录下的内容就有点多了。简单点说,就是你在项目中使用到的所有图片,布局,字符串等资源都要存放在这个目录下。当然这个目录下还有很多子目录,图片放在drawable目录下,布局放在layout目录下,字符串放在values目录下,所以你不用担心会把整个res目录弄得乱糟糟的。
6、AndroidManifest.xml
         这是你整个Android项目的配置文件,你在程序中定义的所以四大组件都需要在这个文件里注册,另外还可以在这个文件中给应用程序添加权限声明。
7、test
         此处是用来编写Unit Test测试用例的,是对项目进行自动化测试的另一种方式。
8、.gitignore
         这个文件用于将app模块内的指定的目录或文件排除在版本控制之外,作用和外层的.gitignore文件类似。
9、app.iml
          IntelliJ IDEA项目自动生成的文件,我们不需要关心或修改这个文件中的内容。
10、build.gradle
         这是app模块的gradle构建脚本,这个文件中会指定很多项目构建相关的配置。
11、proguard-rules.pro
         这个文件用于指定项目代码的混淆规则,当代码开发完成后打成安装包文件,如果不希望代码被别人破解,通常会将代码混淆,从而让破解者难以阅读。

项目中的资源


          如果你展开res目录看一下,其实里面的东西还是挺多的,很容易让人看得眼花缭乱,如下图:


         看到这么多的文件夹也不用害怕,其实归纳一下,res目录就变得非常简单了。
所以以drawable开头的文件夹都是用来放图片的,
所有以mipmap开头的文件夹都是用来放应用图标的,
所有以values开头的文件夹都是用来放字符串、样式、颜色等配置的,
layout文件夹是用来放布局文件的。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324625933&siteId=291194637