项目中修改config.gradle,各个引用的模块便可以自动生效,保持gradle引用库版本的一致,有助于项目模块化开发。
创建config.gradle文件:
文件内容:
ext {
plugins = [library : 'com.android.library',
application: 'com.android.application',
maven : 'com.github.dcendents.android-maven',
bintray : 'com.jfrog.bintray']
android = [applicationId : "com.***.***",
compileSdkVersion : 29,
buildToolsVersion : "27.0.3",
minSdkVersion : 19,
targetSdkVersion : 29,
testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner",
librayMinSdkVersion : 19,
libraryTargetSdkVersion : 29,
versionCode : 1,
versionName : "V1.0.1",]
dependencies = [junit : 'junit:junit:4.12',
expressoCore : 'androidx.test.espresso:espresso-core:3.2.0',
appCompat : 'androidx.appcompat:appcompat:1.1.0',
constraintlayout : 'androidx.constraintlayout:constraintlayout:1.1.3',
//okhttp----nohttp
nohttp : 'com.yanzhenjie.nohttp:nohttp:1.1.11',
okhttp : 'com.yanzhenjie.nohttp:okhttp:1.1.11',
//Baserecyclerview,列表
BaseRecyclerViewAdapterHelper: 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.49-androidx',
//fastjson
fastjson : 'com.alibaba:fastjson:1.1.68.android',
//androidx版本,支持android 10,永久维护,EasyPhotos,拍照,从相册取照片
EasyPhotos : 'com.github.HuanTanSheng:EasyPhotos:3.0.3',
//资源压缩
silicompressor : 'com.iceteck.silicompressorr:silicompressor:2.2.2',
//各种图表,MPAndroidChart
MPAndroidChart : 'com.github.PhilJay:MPAndroidChart:v3.1.0',
//glide,图片加载
glide : 'com.github.bumptech.glide:glide:4.10.0',
//处理代码混淆
multidex : 'com.android.support:multidex:1.0.3',
//butterknife,插件
butterKnife : 'com.jakewharton:butterknife:8.2.0',
butterKnifeCompiler : 'com.jakewharton:butterknife-compiler:8.2.0',
//特别效果输入框
material : 'com.google.android.material:material:1.0.0']
}
使用:
首先需要在项目的grad了文件中添加声明
apply from: "config.gradle"
module中的使用
apply plugin: rootProject.ext.plugins.application
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
defaultConfig {
applicationId rootProject.ext.android.applicationId
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
testInstrumentationRunner rootProject.ext.android.testInstrumentationRunner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation rootProject.ext.dependencies.appCompat
implementation rootProject.ext.dependencies.constraintlayout
testImplementation rootProject.ext.dependencies.junit
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation rootProject.ext.dependencies.expressoCore
implementation rootProject.ext.dependencies.material
implementation rootProject.ext.dependencies.butterKnife
annotationProcessor rootProject.ext.dependencies.butterKnifeCompiler
implementation rootProject.ext.dependencies.multidex
implementation rootProject.ext.dependencies.nohttp
implementation rootProject.ext.dependencies.okhttp
implementation rootProject.ext.dependencies.fastjson
implementation rootProject.ext.dependencies.EasyPhotos
implementation(rootProject.ext.dependencies.glide) {
exclude group: "com.android.support"
}
implementation rootProject.ext.dependencies.BaseRecyclerViewAdapterHelper
implementation rootProject.ext.dependencies.MPAndroidChart
implementation rootProject.ext.dependencies.silicompressor
}