配置config.gradle
ext {
isRelease = false
androidId = [
"compileSdkVersion": 29,
"buildToolsVersion": "29.0.1",
"minSdkVersion" : 21,
"targetSdkVersion" : 29,
"versionCode" : 1,
"versionName" : "1.0"
]
url = [
"debug" : "htts://www.google.com",
"release": "htts://www.facebook.com"
]
appId = [
"applicationId": "com.easy.combine_module"
]
androidX = "1.1.0"
dependencies = [
"appcompat" : "androidx.appcompat:appcompat:${androidX}",
"constraintlayout": "androidx.constraintlayout:constraintlayout:1.1.3",
"legacySupportV4" : "androidx.legacy:legacy-support-v4:1.0.0",
"viewpager" : "androidx.viewpager:viewpager:1.0.0"
]
}
引入:apply from: "config.gradle"
build.gradle使用
apply plugin: 'com.android.application'
def androidId = rootProject.ext.androidId
def url = rootProject.ext.url
def support = rootProject.ext.dependencies
android {
compileSdkVersion androidId.compileSdkVersion
buildToolsVersion androidId.buildToolsVersion
defaultConfig {
applicationId androidId.applicationId
minSdkVersion androidId.minSdkVersion
targetSdkVersion androidId.targetSdkVersion
versionCode androidId.versionCode
versionName androidId.versionName
// 開啟分包
multiDexEnabled true
// 設置分包配置
// multiDexKeepFile file('multidex-config.txt')
// 將svg圖片生成 指定維度的png圖片
// vectorDrawables.generatedDensities('xhdpi','xxhdpi')
// 使用support-v7兼容(5.0版本以上)
vectorDrawables.useSupportLibrary = true
// 只保留指定和默認資源
resConfigs('zh-rCN')
// 配置so庫CPU架構(真機:arm,模擬器:x86)
// x86 x86_64 mips mips64
ndk {
//abiFilters('armeabi', 'armeabi-v7a')
// 為了模擬器啟動
abiFilters('x86', 'x86_64')
}
// 源集 - 設置源集的屬性始苇,更改源集的 Java 目錄或者自由目錄等
sourceSets {
main {
if (!isRelease) {
// 如果是組件化模式梁棠,需要單獨運行時
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
resources.srcDirs = ['src/main/resources']
aidl.srcDirs = ['src/main/aidl']
assets.srcDirs = ['src/main/assets']
} else {
// 集成化模式诚欠,整個項目打包
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
signingConfigs {
debug {
// 天坑:填錯了王暗,編譯不通過還找不到問題
storeFile file('/Users/wangtao/.android/debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
// 簽名證書文件
storeFile file('./module.key')
// 簽名證書的類型
storeType "taoge666"
// 簽名證書文件的密碼
storePassword "taoge666"
// 簽名證書中密鑰別名
keyAlias "taoge"
// 簽名證書中該密鑰的密碼
keyPassword "taoge123"
// 是否開啟V2打包
v2SigningEnabled true
}
}
buildTypes {
debug {
buildConfigField("String", "debug", "\"${url.debug}\"")
}
release {
minifyEnabled false
buildConfigField("release", "release", "\"${url.release}\"")
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
support.each { k, v -> implementation v }
}