优化打包脚本,兼容低版本AndroidStudio使用
This commit is contained in:
parent
3f1fe93f3d
commit
f1a1aae787
@ -23,4 +23,5 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// api 'com.google.code.gson:gson:2.8.8'
|
||||||
}
|
}
|
112
app/build.gradle
112
app/build.gradle
@ -4,10 +4,8 @@ apply plugin: 'com.google.gms.google-services'
|
|||||||
apply plugin: 'com.google.firebase.crashlytics'
|
apply plugin: 'com.google.firebase.crashlytics'
|
||||||
apply plugin: 'com.alibaba.arouter'
|
apply plugin: 'com.alibaba.arouter'
|
||||||
apply from: "../package_config.gradle"
|
apply from: "../package_config.gradle"
|
||||||
|
|
||||||
android {
|
android {
|
||||||
dexOptions {
|
|
||||||
jumboMode = true
|
|
||||||
}
|
|
||||||
project.tasks.getByName("tasks").doFirst {
|
project.tasks.getByName("tasks").doFirst {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -90,12 +88,13 @@ android {
|
|||||||
|
|
||||||
applicationVariants.all { variant ->
|
applicationVariants.all { variant ->
|
||||||
println "清空build文件夹";
|
println "清空build文件夹";
|
||||||
for (final def project in rootProject.getAllprojects()) {
|
/* for (final def project in rootProject.getAllprojects()) {
|
||||||
def name = variant.name.replace('Debug', '').replace('Release', '').toLowerCase()
|
def name = variant.name.replace('Debug', '').replace('Release', '').toLowerCase()
|
||||||
delete project.buildDir
|
delete project.buildDir
|
||||||
delete 'app' + File.separator + name
|
delete project.rootDir.absolutePath+File.separator+"app"+File.separator+name
|
||||||
println project.buildDir
|
println project.buildDir
|
||||||
}
|
}*/
|
||||||
|
//delete project.rootDir.absolutePath + File.separator + "outputs"
|
||||||
String variantName = variant.name.capitalize()
|
String variantName = variant.name.capitalize()
|
||||||
def processManifestTask = project.tasks.getByName("process${variantName}Manifest")
|
def processManifestTask = project.tasks.getByName("process${variantName}Manifest")
|
||||||
processManifestTask.doLast { pm ->
|
processManifestTask.doLast { pm ->
|
||||||
@ -160,29 +159,39 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
variant.outputs.all { vt ->
|
variant.assemble.doLast { vt ->
|
||||||
println("输出文件名:${vt}")
|
|
||||||
def channel = ''
|
def channel = ''
|
||||||
def server=''
|
def server = ''
|
||||||
if (variant.name.startsWith('huawei')) {
|
if (variant.name.contains('huawei')) {
|
||||||
channel = "华为"
|
channel = "华为"
|
||||||
} else if (variant.name.startsWith('samsung')) {
|
} else if (variant.name.contains('samsung')) {
|
||||||
channel = "三星"
|
channel = "三星"
|
||||||
} else if (variant.name.startsWith('google')) {
|
} else if (variant.name.contains('google')) {
|
||||||
channel = "谷歌"
|
channel = "谷歌"
|
||||||
} else {
|
} else {
|
||||||
channel = "链接"
|
channel = "链接"
|
||||||
}
|
}
|
||||||
if(variant.name.contains('online')){
|
if (variant.name.contains('online')) {
|
||||||
server='正式服'
|
server = '正式服'
|
||||||
}else{
|
} else {
|
||||||
server='测试服'
|
server = '测试服'
|
||||||
}
|
}
|
||||||
outputFileName = "[${new Date().format("yyyy-MM-dd HHmmss", TimeZone.getTimeZone("GMT+8"))}]PDLive-${defaultConfig.versionName}-${channel}-${server}-${variant.buildType.name}.apk"
|
def fileName = "[${new Date().format("yyyy-MM-dd HHmmss", TimeZone.getTimeZone("GMT+8"))}]PDLive-${defaultConfig.versionName}-${defaultConfig.versionCode}-${channel}-${server}-${variant.buildType.name}.apk"
|
||||||
|
variant.outputs.forEach { fe ->
|
||||||
|
copy {
|
||||||
|
from fe.outputFile
|
||||||
|
into file("${project.rootDir}\\outputs\\apk\\")
|
||||||
|
rename { fn ->
|
||||||
|
fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
tasks.named("sign${variant.name.capitalize()}Bundle", com.android.build.gradle.internal.tasks.FinalizeBundleTask) {
|
tasks.named("sign${variant.name.capitalize()}Bundle", com.android.build.gradle.internal.tasks.FinalizeBundleTask) {
|
||||||
File file = finalBundleFile.asFile.get()
|
File file = finalBundleFile.asFile.get()
|
||||||
def channel = ''
|
def channel = ''
|
||||||
|
def server = ''
|
||||||
if (variant.name.startsWith('huawei')) {
|
if (variant.name.startsWith('huawei')) {
|
||||||
channel = "华为"
|
channel = "华为"
|
||||||
} else if (variant.name.startsWith('samsung')) {
|
} else if (variant.name.startsWith('samsung')) {
|
||||||
@ -192,44 +201,15 @@ android {
|
|||||||
} else {
|
} else {
|
||||||
channel = "链接"
|
channel = "链接"
|
||||||
}
|
}
|
||||||
File finalFile = new File(file.parentFile, "[${new Date().format("yyyy-MM-dd HHmmss", TimeZone.getTimeZone("GMT+8"))}]PDLive-${defaultConfig.versionName}-${channel}-${variant.buildType.name}.aab")
|
if (variant.name.contains('online')) {
|
||||||
|
server = '正式服'
|
||||||
|
} else {
|
||||||
|
server = '测试服'
|
||||||
|
}
|
||||||
|
def fileName = "[${new Date().format("yyyy-MM-dd HHmmss", TimeZone.getTimeZone("GMT+8"))}]PDLive-${defaultConfig.versionName}-${defaultConfig.versionCode}-${channel}-${server}-${variant.buildType.name}.aab"
|
||||||
|
File finalFile = new File("${project.rootDir}\\outputs\\aab", fileName)
|
||||||
finalBundleFile.set(finalFile)
|
finalBundleFile.set(finalFile)
|
||||||
}
|
}
|
||||||
project.afterEvaluate { project ->
|
|
||||||
project.tasks.each {
|
|
||||||
if (it.name.startsWith('assemble') && it.name.endsWith('Release')) {
|
|
||||||
it.doLast {
|
|
||||||
def dir = it.name.replace('assemble', '').replace('Release', '').toLowerCase()
|
|
||||||
println("处理assembleRelease ${project.rootDir}\\app\\$dir\\release\\ | " + new File("${project.rootDir}\\app\\$dir\\release\\").exists())
|
|
||||||
if (new File("${project.rootDir}\\app\\$dir\\release\\").exists()) {
|
|
||||||
println("准备拷贝apk文件")
|
|
||||||
copy {
|
|
||||||
from file("${project.rootDir}\\app\\$dir\\release\\")
|
|
||||||
into file("${project.rootDir}\\outputs\\apk\\")
|
|
||||||
include '**/*.apk'
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
println("打包apk结束")
|
|
||||||
}
|
|
||||||
} else if (it.name.startsWith('sign') && it.name.endsWith('ReleaseBundle')) {
|
|
||||||
it.doLast {
|
|
||||||
def dir = it.name.replace('sign', '').replace('ReleaseBundle', '').toLowerCase()
|
|
||||||
println("处理signReleaseBundle ${project.rootDir}\\app\\$dir\\release\\ | " + new File("${project.rootDir}\\app\\$dir\\release\\").exists())
|
|
||||||
if (new File("${project.rootDir}\\app\\$dir\\release\\").exists()) {
|
|
||||||
println("准备拷贝aab文件")
|
|
||||||
copy {
|
|
||||||
from file("${project.rootDir}\\app\\$dir\\release\\")
|
|
||||||
into file("${project.rootDir}\\outputs\\aab\\")
|
|
||||||
include '**/*.aab'
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
println("打包aab结束")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
@ -269,9 +249,17 @@ android {
|
|||||||
manifestPlaceholders = rootProject.ext.manifestPlaceholders
|
manifestPlaceholders = rootProject.ext.manifestPlaceholders
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
// TODO: 谷歌商城需要兼容两个平台
|
Gradle gradle = getGradle()
|
||||||
//abiFilters "armeabi-v7a", "arm64-v8a"
|
String tskReqStr = gradle.getStartParameter().getTaskRequests().args.toString()
|
||||||
|
println("处理ndk 版本 = " + tskReqStr)
|
||||||
|
def isLink = tskReqStr.contains("Link")
|
||||||
|
if (isLink) {
|
||||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||||
|
println("打包ndk 链接")
|
||||||
|
} else {
|
||||||
|
abiFilters "armeabi-v7a", "arm64-v8a"
|
||||||
|
println("打包ndk其他")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
javaCompileOptions {
|
javaCompileOptions {
|
||||||
annotationProcessorOptions {
|
annotationProcessorOptions {
|
||||||
@ -327,17 +315,3 @@ dependencies {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// 链接包需要注释掉 否正无法更新 谷歌包需要打开
|
|
||||||
/*
|
|
||||||
project.afterEvaluate {
|
|
||||||
android.applicationVariants.all { variant ->
|
|
||||||
variant.outputs.each { output ->
|
|
||||||
output.processResources.doFirst { pm->
|
|
||||||
String manifestPath = output.processResources.manifestFile;
|
|
||||||
def manifestContent = file(manifestPath).getText()
|
|
||||||
manifestContent = manifestContent.replace('android.permission.REQUEST_INSTALL_PACKAGES', '')
|
|
||||||
file(manifestPath).write(manifestContent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
@ -4,8 +4,8 @@ ext {
|
|||||||
buildToolsVersion: "29.0.2",
|
buildToolsVersion: "29.0.2",
|
||||||
minSdkVersion : 21,
|
minSdkVersion : 21,
|
||||||
targetSdkVersion : 33,
|
targetSdkVersion : 33,
|
||||||
versionCode : 678,
|
versionCode : 681,
|
||||||
versionName : "6.7.0"
|
versionName : "6.7.1"
|
||||||
]
|
]
|
||||||
manifestPlaceholders = [
|
manifestPlaceholders = [
|
||||||
//正式、
|
//正式、
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
android{
|
android{
|
||||||
|
dexOptions {
|
||||||
|
jumboMode = true
|
||||||
|
javaMaxHeapSize "8g"
|
||||||
|
preDexLibraries = true
|
||||||
|
threadCount = 8
|
||||||
|
}
|
||||||
|
|
||||||
flavorDimensions 'packageApk'
|
flavorDimensions 'packageApk'
|
||||||
productFlavors {
|
productFlavors {
|
||||||
link_test {
|
link_test {
|
||||||
|
Loading…
Reference in New Issue
Block a user