1、在项目根目录下新建一个配置文件,例如:config.gradle【随便取名】
2、在项目根目录下的build.gradle文件头,引用配置文件,例如:apply from: "config.gradle"
3、app或lib目录下的build.gradle文件里引用:
方法一:rootProject.【配置文件标签】.【子标签】["【key】"]
方法二:rootProject.【配置文件标签】.【子标签】.【key】
例如:
config.gradle 文件:
/** * 全局统一配置 */ ext { /** * 版本统一管理 */ versions = [ /* * 指纹识别 * */ fingerprintVersionCode : 23, fingerprintVersionName : "0.2.3", /* * 虹软面部识别 * */ arcFaceVersionCode : 1, arcFaceVersionName : "0.0.1", compileSdkVersion : 29, minSdkVersion : 19, targetSdkVersion : 29, androidSupportSdkVersion: "29.0.0", appcompatVersion : "1.0.2", constraintlayoutVersion : "1.1.3", junitVersion : "4.12", runnerVersion : "1.2.0", espressoVersion : "3.2.0" ] dependencies = [ "appcompat" : "androidx.appcompat:appcompat:${versions["appcompatVersion"]}", "constraintlayout" : "androidx.constraintlayout:constraintlayout:${versions["constraintlayoutVersion"]}", "runner" : "androidx.test:runner:${versions["runnerVersion"]}", "espresso_core" : "androidx.test.espresso:espresso-core:${versions["espressoVersion"]}", "junit" : "junit:junit:${versions["junitVersion"]}", //注释处理器 "support_annotations": "com.android.support:support-annotations:${versions["androidSupportSdkVersion"]}" ] }
目录根目录build.gradle文件:
apply from: "config.gradle"
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
app或lib目录下build.gradle文件:
defaultConfig { applicationId "com.hailong.biometrics.fingerprint.example" minSdkVersion rootProject.ext.versions.minSdkVersion targetSdkVersion rootProject.ext.versions.targetSdkVersion versionCode rootProject.ext.versions.fingerprintVersionCode versionName rootProject.ext.versions.fingerprintVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true }
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation rootProject.ext.dependencies["appcompat"] implementation rootProject.ext.dependencies["junit"] implementation rootProject.ext.dependencies["runner"] implementation rootProject.ext.dependencies["espresso_core"] implementation rootProject.ext.dependencies["constraintlayout"] implementation project(':fingerprint') // implementation "com.github.ZuoHailong:BiometricPrompt:0.2.3" }