build.gradle file

1 Introduction

Android studioIt is gradleused to build the project.

2. ProjectUnder the build.gradlefile

But because gradlethis project build tool is not written specifically for Androiddevelopment, it can support other languages, such as Java, C++etc. Therefore build.gradle, you need to specify the gradleversion 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 repositoriesis to specify the warehouse address, because we will use jcentersome open source projects in this open source library.
The current gradleversion is specified as3.5.2

3. appUnder the build.gradlefile

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 pluginis the plug-in meaning.

In defaultConfigour simple configuration of the project. Such as: applicationIda package name specified item
in buildTypesthe designated installation configuration file generated. For example, it is minifyEnabledused to specify whether to obfuscate the code of the project, and it is proguardFilesused to specify the rule file at the time of confusion. 'proguard-android-optimize.txtIn the Andorid SDKdirectory, which proguard-rules.prois 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 Jaradding 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 jcenterthe dependency on the open source project;

implementation fileTreeIt is a local dependency declaration; it
implementationis a remote dependency declaration, such as: implementation 'androidx.appcompat:appcompat:1.0.2'
implementation project(':helper')library dependency;

Guess you like

Origin blog.csdn.net/qq_26460841/article/details/113438726