gradle application developed by Android (1)

**

Brief introduction

**
1. The build.gradle file in the project, the build.gradle file in the root directory and a build.gradle file under each module, such as the newly created project, the root directory comes with one, and the app module is shown as follows:

2. Because I am used to developing under the android menu, this is how I switch to android. The following picture:

**

Get to the point

**
Tip: if you have any small problems with the update of gradle version, please read the following article.
https://blog.csdn.net/qq_33373648/article/details/81534319

1. First, look at the build.gradle file in the root directory. I write comments directly in the code. At last, the code provides download and sharing links

/**
 * buildscript: Global related properties.
 * repositories: Some warehouse sources are related. The default is jcenter central remote warehouse (compatible with maven central warehouse, better performance)
 * dependencies: Define some build processes (for example, Android gradle plugin)
 */
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
/**
 * It is used to define the default attributes of each module. You can define task s here to represent the warehouse source of all project s
 */
allprojects {
    repositories {
        google()
        jcenter()
    }
}
/**
 * A task named clean (the name can be changed by yourself)
 * The type of task in brackets is delete (equivalent to clearing the package in External Libraries and adding it again)
 */
task clean(type: Delete) {
    delete rootProject.buildDir
}

2. The build.gradle file under app is as follows

//The plug-ins written by google's Android development team can provide all the construction, packaging and testing of Android applications and dependency libraries.
apply plugin: 'com.android.application'
android {
    //api version at compile time
    compileSdkVersion 27
    defaultConfig {
        //Package name (unique identification of application market)
        applicationId "com.gradle.test"
        //Minimum compatible version
        minSdkVersion 21
        //Target version
        targetSdkVersion 27
        //Version number (will be increased when the version is updated)
        versionCode 1
        //Version name (shown to client users)
        versionName "1.0"
        //Android JUnit runner is set as the default testinstrumentation runner
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    //Compile package version type
    buildTypes {
        release {
            //Is the switch confused
            minifyEnabled false
            //Confusing documents
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
//Various dependency libraries (local dependency, remote dependency)
dependencies {
    //Local dependency on all jar files under libs folder
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //v7 library package
    implementation 'com.android.support:appcompat-v7:27.1.1'
    //Constrained layout
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    //Test related
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Project download address: https://github.com/pengAndroid/gradle_test
If you want to add friends to learn from each other, you can add Q 463263900

Tags: Android Gradle Google Junit

Posted on Mon, 06 Jan 2020 00:33:34 -0800 by abalfazl