优化打包脚本,兼容低版本AndroidStudio使用
This commit is contained in:
parent
3f1fe93f3d
commit
f1a1aae787
@ -23,4 +23,5 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// api 'com.google.code.gson:gson:2.8.8'
|
||||
}
|
116
app/build.gradle
116
app/build.gradle
@ -4,10 +4,8 @@ apply plugin: 'com.google.gms.google-services'
|
||||
apply plugin: 'com.google.firebase.crashlytics'
|
||||
apply plugin: 'com.alibaba.arouter'
|
||||
apply from: "../package_config.gradle"
|
||||
|
||||
android {
|
||||
dexOptions {
|
||||
jumboMode = true
|
||||
}
|
||||
project.tasks.getByName("tasks").doFirst {
|
||||
|
||||
}
|
||||
@ -90,12 +88,13 @@ android {
|
||||
|
||||
applicationVariants.all { variant ->
|
||||
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()
|
||||
delete project.buildDir
|
||||
delete 'app' + File.separator + name
|
||||
delete project.rootDir.absolutePath+File.separator+"app"+File.separator+name
|
||||
println project.buildDir
|
||||
}
|
||||
}*/
|
||||
//delete project.rootDir.absolutePath + File.separator + "outputs"
|
||||
String variantName = variant.name.capitalize()
|
||||
def processManifestTask = project.tasks.getByName("process${variantName}Manifest")
|
||||
processManifestTask.doLast { pm ->
|
||||
@ -160,29 +159,39 @@ android {
|
||||
}
|
||||
}
|
||||
}
|
||||
variant.outputs.all { vt ->
|
||||
println("输出文件名:${vt}")
|
||||
variant.assemble.doLast { vt ->
|
||||
def channel = ''
|
||||
def server=''
|
||||
if (variant.name.startsWith('huawei')) {
|
||||
def server = ''
|
||||
if (variant.name.contains('huawei')) {
|
||||
channel = "华为"
|
||||
} else if (variant.name.startsWith('samsung')) {
|
||||
} else if (variant.name.contains('samsung')) {
|
||||
channel = "三星"
|
||||
} else if (variant.name.startsWith('google')) {
|
||||
} else if (variant.name.contains('google')) {
|
||||
channel = "谷歌"
|
||||
} else {
|
||||
channel = "链接"
|
||||
}
|
||||
if(variant.name.contains('online')){
|
||||
server='正式服'
|
||||
}else{
|
||||
server='测试服'
|
||||
if (variant.name.contains('online')) {
|
||||
server = '正式服'
|
||||
} else {
|
||||
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) {
|
||||
File file = finalBundleFile.asFile.get()
|
||||
def channel = ''
|
||||
def server = ''
|
||||
if (variant.name.startsWith('huawei')) {
|
||||
channel = "华为"
|
||||
} else if (variant.name.startsWith('samsung')) {
|
||||
@ -192,43 +201,14 @@ android {
|
||||
} else {
|
||||
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")
|
||||
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结束")
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
signingConfigs {
|
||||
@ -269,9 +249,17 @@ android {
|
||||
manifestPlaceholders = rootProject.ext.manifestPlaceholders
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
// TODO: 谷歌商城需要兼容两个平台
|
||||
//abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
Gradle gradle = getGradle()
|
||||
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"
|
||||
println("打包ndk 链接")
|
||||
} else {
|
||||
abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
println("打包ndk其他")
|
||||
}
|
||||
}
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
@ -326,18 +314,4 @@ dependencies {
|
||||
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
||||
|
||||
|
||||
}
|
||||
// 链接包需要注释掉 否正无法更新 谷歌包需要打开
|
||||
/*
|
||||
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",
|
||||
minSdkVersion : 21,
|
||||
targetSdkVersion : 33,
|
||||
versionCode : 678,
|
||||
versionName : "6.7.0"
|
||||
versionCode : 681,
|
||||
versionName : "6.7.1"
|
||||
]
|
||||
manifestPlaceholders = [
|
||||
//正式、
|
||||
|
@ -1,4 +1,11 @@
|
||||
android{
|
||||
dexOptions {
|
||||
jumboMode = true
|
||||
javaMaxHeapSize "8g"
|
||||
preDexLibraries = true
|
||||
threadCount = 8
|
||||
}
|
||||
|
||||
flavorDimensions 'packageApk'
|
||||
productFlavors {
|
||||
link_test {
|
||||
|
Loading…
Reference in New Issue
Block a user