其他分享
首页 > 其他分享> > Android Gradle

Android Gradle

作者:互联网

自定义Gradle配置文件

1)创建自定义custom.gradle

ext {
    android = [
            compileSdkVersion : 30,
            buildToolsVersion : "30.0.2",
            minSdkVersion : 19,
            targetSdkVersion : 30
    ]

    dependencies = [
            "glide" : "com.github.bumptech.glide:glide:4.11.0"
    ]
}

2)在build.gradle中引入自定义gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

// ***************** 就是加入这个 *****************
apply from : "custom.gradle"

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

3)替换app/build.gradle中的内容

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion rootProject.ext.android["compileSdkVersion"]
    buildToolsVersion rootProject.ext.android["buildToolsVersion"]

    defaultConfig {
        applicationId "com.example.mycustomgradleconfigtest"
        minSdkVersion rootProject.ext.android["minSdkVersion"]
        targetSdkVersion rootProject.ext.android["targetSdkVersion"]
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.+'

    implementation rootProject.ext.dependencies["glide"]
}

在这里插入图片描述

标签:gradle,ext,dependencies,rootProject,Android,Gradle,com,android
来源: https://blog.csdn.net/yan13507001470/article/details/123649043