1、写一个.gradle配置文件
在Progject里面新建一个config.gradle文件,然后里面添加工程需要的配置。如图所示:
2、在Project的build.gradle里面添加配置
9BFB2262-B39F-4065-B8E4-45577E3E5D81.png
3、在module的build.gradle里面引用即可
代码语言:javascript复制def config=rootProject.ext.android//配置
def librarys=rootProject.ext.dependencies//依赖
android {
compileSdkVersion config.compileSdkVersion
buildToolsVersion config.buildToolsVersion
defaultConfig {
applicationId "cn.project.demo.com"
minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion
versionCode config.versionCode
versionName config.versionName
}
//签名--->微信分享、登录,就不用打包了。直接运行即可。
signingConfigs{
//这里debug和release其实是一样的
// debug{
// storeFile file("签名文件路径")
// storePassword "签名文件存储密码"
// keyAlias "签名文件标识"
// keyPassword "签名文件密码"
// }
// release{
// storeFile file("签名文件路径")
// storePassword "签名文件存储密码"
// keyAlias "签名文件标识"
// keyPassword "签名文件密码"
// }
}
buildTypes {
debug{
applicationIdSuffix ".test"
zipAlignEnabled false
minifyEnabled false
buildConfigField("boolean","LOG_DEBUG","true")
buildConfigField("String","BASE_URL",'"debugurl"')
buildConfigField("String","H5_URL",'"debugurl"')
resValue("string","app_name","ProjectDemoDebug")
// signingConfig signingConfigs.debug
}
release {
zipAlignEnabled true
minifyEnabled true
buildConfigField("boolean","LOG_DEBUG","false")
buildConfigField("String","BASE_URL",'"releaseurl"')
buildConfigField("String","H5_URL",'"releaseurl"')
resValue("string","app_name","ProjectDemoRelease")
// signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile librarys.supportV7
compile librarys.supportV4
compile librarys.constraintlayout
compile librarys.design
compile librarys.recyclerview
compile librarys.stetho
compile librarys.stethoRealm
compile librarys.gson
}
好了,具体就是这三个步骤,以后新建工程都可以直接使用这样的配置,就不需要去找相应的库了。