安卓工程同一管理gradle变量

源码 2024-10-7 09:59:08 62 0 来自 中国
我们复制一个gradle文件 然后重新定名一个与项目相干的名字

打开imooc.gradle文件,重新界说一下内里的内容
ext {    android = [            applicationId:'com.tencent.musicproject',            compileSdkVersion: 28,            minSdkVersion    : 19,            targetSdkVersion : 28,            versionCode      : 1,            versionName      : '1.0'    ]    //三方版本号    depsVersion = [            appcompat: '1.4.0'    ]    //三方地点    depsLibs = [           appcompat:"androidx.appcompat:appcompat{depsVersion.appcompat}"    ]}我们把项目中的全部版本号信息 依靠项 都编辑到内里 创建数组名称自界说 来管理对应的版本号和依靠
这内里depsLibs 内里要用双引号,由于中心利用了$符号,单引号失去结果
编辑好imooc.gradle文件后 必要在工程的总build.gradle文件中引入该文件
apply from : file('imooc.gradle')//apply from: this.rootProject.file('imooc.gradle')引入完毕重新构建一下项目 就可以在项目中进行更换了
apply plugin: 'com.android.application'android {    compileSdkVersion this.rootProject.android.compileSdkVersion    buildToolsVersion "30.0.0"    defaultConfig {        applicationId this.rootProject.android.applicationId        minSdkVersion this.rootProject.android.minSdkVersion        targetSdkVersion this.rootProject.android.targetSdkVersion        versionCode this.rootProject.android.versionCode        versionName this.rootProject.android.versionName        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'        }    }    configurations.all {        resolutionStrategy {            force 'androidx.core:core-ktx:1.6.0'        }    }}dependencies {    implementation fileTree(dir: "libs", include: ["*.jar"])    implementation this.rootProject.depsLibs.appcompat    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'androidx.test.ext:junit:1.1.3'    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'}
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:44, Processed in 0.177730 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表