Write a custom catalog title here
1 Introduction
Android studio
It is gradle
used to build the project.
2. Project
Under the build.gradle
file
But because gradle
this project build tool is not written specifically for Android
development, it can support other languages, such as Java
, C++
etc. Therefore build.gradle
, you need to specify the gradle
version that the project depends on in the file of the current project .
Such as:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
}
}
allprojects {
repositories {
jcenter()
}
}
However, what you see above repositories
is to specify the warehouse address, because we will use jcenter
some open source projects in this open source library.
The current gradle
version is specified as3.5.2
3. app
Under the build.gradle
file
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
The first line specifies whether it is an application module or a library module. Generally, there are two values to choose from:
com.android.application
com.android.library
More interesting plugin
is the plug-in meaning.
In defaultConfig
our simple configuration of the project. Such as: applicationId
a package name specified item
in buildTypes
the designated installation configuration file generated. For example, it is minifyEnabled
used to specify whether to obfuscate the code of the project, and it is proguardFiles
used to specify the rule file at the time of confusion. 'proguard-android-optimize.txt
In the Andorid SDK
directory, which proguard-rules.pro
is in the root directory of the current project, the details of the file has an official address: here Wallpaper .
In dependencies
, it is used to specify the dependencies of the current project. There are three types of dependencies:
- Local dependency
- Library dependency
- Remote dependency
Local dependency means Jar
adding a dependency to the local or directory;
library dependency means that you can add dependency to the library module in the project;
remote dependency means jcenter
the dependency on the open source project;
implementation fileTree
It is a local dependency declaration; it
implementation
is a remote dependency declaration, such as: implementation 'androidx.appcompat:appcompat:1.0.2'
implementation project(':helper')
library dependency;