1.增加签名文件
signingConfigs {
sign_q {
keyAlias 'key1'
keyPassword '111111'
storeFile file('storefile/sskey.jks')
storePassword '111111'
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
对release 版本用sskey.jks文件签名
signingConfig signingConfigs.sign_q
}
debug {
minifyEnabled false
signingConfig signingConfigs.sign_q
}
}
对于android 系统中,如何制作系统签名jks,可以参考我这篇文章 各位大佬都是怎么开发调试系统应用的
2.输出特定apk名称
android.applicationVariants.all { variant ->
variant.outputs.all {
variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + File.separator + "outputs")
def apkName = "${variant.productFlavors.name}_${variant.buildType.name}_${variant.productFlavors[0].versionName}"
outputFileName = apkName + ".apk"
}
}
3.分渠道编译
可参考另一篇文章android 差异化多渠道打包
flavorDimensions "os_backup"
productFlavors {
os_backup {
applicationId 'com.test.backup'
versionCode 2
versionName "2.0".concat("_").concat(releaseTime())
}
os_phoneclone {
applicationId 'com.test.phoneclone'
versionCode 4
versionName "2.0".concat("_").concat(releaseTime())
minSdkVersion 21
}
}
def releaseTime() {
return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))
}
4.选择性打包
defaultConfig {
applicationId "com.example.miracastdemo"
minSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
resConfigs("xxhdpi","xxxhdpi")
resConfigs("en","zh","zh-rCN")
ndk {
abiFilters 'armeabi-v7a'
}
}
sourceSets {
os_backup {
res.srcDirs = ['res']
java.srcDirs = ['src', 'src_plugins']
manifest.srcFile 'AndroidManifest-common.xml'
}
os_phoneclone {
res.srcDirs = ['res']
java.srcDirs = ['src', 'src_plugins']
manifest.srcFile 'AndroidManifest-common.xml'
}
}
5 .引入依赖
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// 引入libs 下的所有jar 包和aar 包
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.aar'], dir: 'libs')
//noinspection GradleCompatible,GradleCompatible
implementation 'com.android.support:support-v13:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
// 引入libs单个的aar 包
compile(name: 'zxing-android-embedded-3.6.0', ext: 'aar')
compile(name: 'lottie-2.7.0', ext: 'aar')
6.混淆
buildTypes {
release {
minifyEnabled false
//混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sign_wingos_q
}
debug {
minifyEnabled false
signingConfig signingConfigs.sign_wingos_q
}
}
7. android.mk 中选择性文件打包
LOCAL_PATH := $(call my-dir)include$(CLEAR_VARS)
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT:=false
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-v7-appcompat \
android-support-v17-leanback
LOCAL_STATIC_JAVA_LIBRARIES := \
com.mediatek.support.tv \
androidx.annotation_annotation
LOCAL_PRIVATE_PLATFORM_APIS := true
// mk 打包时选择性的引入对应的文件
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_ASSET_DIR := $(LOCAL_PATH)/app/src/main/assets
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
LOCAL_PACKAGE_NAME := Demo
|