apply plugin: 'com.android.application'
// Keystore 签名
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 32
defaultConfig {
applicationId "com.test.test"
minSdkVersion 21
targetSdkVersion 32
versionCode 101
versionName '1.0.1'
// 代码中调用 BuildConfig.IS_PRO_ENV 判断是否是生产环境
buildConfigField "boolean", "IS_PRO_ENV", "false"
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a'
//选择要添加的对应cpu类型的.so库。还可以添加 'armeabi-v7a', 'arm64-v8a' ,'x86', 'x86_64', 'mips', 'mips64'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
v1SigningEnabled true // 开启V1签名
v2SigningEnabled false
}
}
// 配置打包后的文件名称
android.applicationVariants.all { variant ->
variant.outputs.all {
def buildType = "debug"
if (variant.buildType.name == "release") {
buildType = "release"
}
outputFileName = "appName_${releaseTime()}_${buildType}_${defaultConfig.versionName}.apk"
}
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
applicationIdSuffix ".release" // 正式版 applicationId 添加前缀
// debug 和 release 打包,应用名称和 第三方 Key 等均可各自设置
manifestPlaceholders = [app_name_value: "测试应用",
baidumap_api_key: "ABCDEFGHIJKLMN"
]
buildConfigField "boolean", "IS_PRO_ENV", "true"
multiDexKeepProguard file ("multidex-config.pro")
}
debug {
debuggable false //生产环境时为false
signingConfig signingConfigs.config
// debug 和 release 打包,应用名称和 第三方 Key 等均可各自设置
manifestPlaceholders = [app_name_value: "测试应用(测试)",
baidumap_api_key: "123456789"
]
buildConfigField "boolean", "IS_PRO_ENV", "false"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
res.srcDirs =
[
'src/main/res/layouts',
'src/main/res/layout',
'src/main/res'
]
}
}
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
def releaseTime() {
return new Date().format("yyyyMMdd_HHmm", TimeZone.getTimeZone("GMT+08:00"))
}
dependencies {
// 放在 libs 文件夹下的 jar 包
implementation files('libs/json-lib-2.4-jdk15.jar')
// Module
implementation project(':imageLoader')
// 从第三方库中排除引起冲突的部分
implementation ('com.github.thirdparty:1.1.1') {
exclude group: 'androidx.annotation', module: 'annotation'
}
}
keystore.properties
文件放在项目根目录下,与 settings.gradle
等同级。
内容如下:
storePassword=pw123
keyPassword=pw123
keyAlias=test
storeFile=D:\\keystore\\test.keystore
buildTypes 中定义的 manifestPlaceholders 在 AndroidManifest.xml
中这样使用:
<application
android:name="com.test.test.MyApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="${app_name_value}"
tools:replace="android:label"
android:theme="@android:style/Theme.NoTitleBar">
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="${baidumap_api_key}" />