1. What is build.gradle?
Build. gradle is a file that configures your project, similar to XML configuration. Gradle of the root node (only one) and build.grdle of the Module (multiple). For example, in our new Android Project, By default, build. Gradle for the root node and build. Gradle for the app module are generated.
2. What can build. Gradle do?
Build. gradle is used to configure your project, such as downloading SDK resources from third-party sources, referencing plug-ins, etc. To make good use of these configurations, we need to be able to use some of the methods provided by Gralde and the Android Gradle Plugin. \
Gradle and Android Gradle Plugin (AGP
First, don’t confuse Gradle with AGP. Gradle is an open source tool for automating project building based on Apache Ant and Apache Maven concepts. Android Plugin for Gradle is a collection of Gradle plugins suitable for Android development. (can be understood as a Java program) \
4. Where is the Android Gradle Plugin introduced?
The root node of the can see in our build. The gradle, have such a classpath “com. Android. View the build: gradle: 4.1.3” above is the introduction of android plugin. Below is the AGP API file developer.android.com/reference/t… \
5. Where does Android Gradle Plugin work?
Plugins {id' com.android.application' id' kotlin-android'} android {compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 23 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' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility Javon_1_8} kotlinOptions {jvmTarget = '1.8'}} dependencies {implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }Copy the code
This picture above, there are three nodes, plugins, android, only android is AGP plug-in dependencies on these nodes above, through the following code AGP is introduced.
plugins {
id 'com.android.application'
}
Copy the code
For example, configure AGP to compileSdkVersion 30
open fun compileSdkVersion(apiLevel: Int) {
compileSdkVersion("android-$apiLevel")
}
Copy the code
Tip1: Download AGP source code locally, In our build. Gradle – > add implementation dependencies “com. Android. View the build: gradle: 4.1.3” tip2: how is difference between AGP plug-in code, there is a simple way, Nodes that cannot see the source code are AGP plug-ins