All configurations you should know when using Android Studio for the first time (3): gradle project construction, androidgradle
[Statement]
Reprinted, but keep the original source of the article → _ →
Life One: http://www.cnblogs.com/smyhvae/
Source: http://www.cnblogs.com/smyhvae/p/4456420.html
Contact: smyhvae@163.com
[Series]
Everything you should know when you use Android Studio for the first time
Everything you should know when using Android Studio for the first time (2): Create a project of your own and install the Genymotion Simulator
All configurations you should know when using Android Studio for the first time (3): gradle Project Build
Directory:
1. gradle Concept
2. Configure the jar package in gradle, which is different from the jar package imported into the libs folder.
3. Signature packaging:
(1) Studio
(2) Command Line
(3) Principle of gradle wrapper
4. Use of BuildConfig
5. Briefly introduce the parameter meaning of the build. gradle file in the module
I. gradle concept:
- Gradle isBuild tools
- Gradle is based on the Groovy Language
- Gradle mainly targets Java
Open the Android Studio built-in terminal and run the following command to view the gradle version:
gradlew -v
If this command is run for the first time, the system will download gradle to the local device. The download path is:
Build. gradle FileIn fact, it correspondsModule configuration file. We will explain the meaning of the specific content in the build. gradle file in the last section.
Let's take a look at the module named app. Its build. gradle graphic interface is actually the following Project Stucture:
Project directoryThere is a build. gradle file, open it:
If we execute the gradlew command, we actually execute the gradle wrapper above and find the gradle 2.2.1 we have downloaded. If there are many projects, but the gradle versions of each project are different, I have to configure the gradle of each version to the environment variable and execute the gradlew command, this will be avoided.
Iv. BuildConfig file:
BuildConfig is a class automatically generated by IDE. It is stored in the gen directory (such as the R file) in elipse ). In Adroid Studio, the BuildConfig file is stored in app/build/generated/source/buildconfig/dubug/<packagename>/BuildConfig. java. As shown in:
V. Meanings of parameters in the build. gradle file in the module:
It is mainly the module build. gradle, as follows:
Row 01: apply plugin: 'com. android. application' indicates that this module is the module of the application.
Row 15: package name of the applicationId "com. smyhvae. helloworld" Application
Lines 16 and 17: Minimum and compiled versions that are backward compatible. Note: This information is no longer displayed in app/src/main/AndroidManifest. xml.
Line 23: you do not need to use the 24-line proguard file.Obfuscation code. In the release status, it is best to change it to true.