181 lines
7.9 KiB
Groovy
181 lines
7.9 KiB
Groovy
import org.gradle.api.execution.*
|
|
import com.android.build.gradle.tasks.*
|
|
import com.android.build.gradle.*
|
|
import org.gradle.process.*
|
|
import org.gradle.api.invocation.*
|
|
|
|
plugins {
|
|
id 'com.android.library'
|
|
id 'org.jetbrains.kotlin.android'
|
|
id 'com.alibaba.arouter'
|
|
id 'kotlin-kapt'
|
|
}
|
|
|
|
android {
|
|
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
|
defaultConfig {
|
|
minSdkVersion rootProject.ext.android.minSdkVersion
|
|
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
|
|
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
consumerProguardFiles "consumer-rules.pro"
|
|
|
|
//ARouter apt 参数
|
|
kapt {
|
|
useBuildCache = false
|
|
arguments {
|
|
arg("AROUTER_MODULE_NAME", project.getName())
|
|
}
|
|
}
|
|
}
|
|
|
|
sourceSets {
|
|
main {
|
|
jniLibs.srcDirs = ['jniLibs']
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled false
|
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
}
|
|
}
|
|
compileOptions {
|
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
}
|
|
kotlinOptions {
|
|
jvmTarget = '1.8'
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
implementation rootProject.ext.dependencies.androidxccorektx
|
|
implementation rootProject.ext.dependencies.androidxappcompat
|
|
implementation rootProject.ext.dependencies.material
|
|
androidTestImplementation rootProject.ext.dependencies.androidxjunit
|
|
androidTestImplementation rootProject.ext.dependencies.junit
|
|
implementation rootProject.ext.dependencies.lancetx_runtime
|
|
implementation rootProject.ext.dependencies.arouter
|
|
kapt rootProject.ext.dependencies.aroutercompiler
|
|
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
|
implementation rootProject.ext.dependencies.moduleservice
|
|
implementation rootProject.ext.dependencies.mogo_core_data
|
|
implementation rootProject.ext.dependencies.mogo_core_utils
|
|
implementation rootProject.ext.dependencies.mogo_core_function_api
|
|
implementation rootProject.ext.dependencies.mogo_core_res
|
|
} else {
|
|
implementation project(':core:mogo-core-data')
|
|
implementation project(':core:mogo-core-utils')
|
|
implementation project(':core:mogo-core-function-api')
|
|
implementation project(':core:mogo-core-res')
|
|
}
|
|
}
|
|
|
|
rootProject.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
|
|
def tasks = graph.allTasks.findAll { t0 ->
|
|
t0 instanceof PackageApplication
|
|
}
|
|
def app = rootProject.subprojects.find {
|
|
it.plugins.hasPlugin("com.android.application")
|
|
}
|
|
if (app != null) {
|
|
def android = (AppExtension)app.extensions.findByName("android")
|
|
def signConfig = android.signingConfigs.getByName("release")
|
|
if (signConfig != null && isOnlineReleaseBuild(gradle)) {
|
|
if (tasks != null) {
|
|
tasks.forEach { t1 ->
|
|
t1.doLast { t2 ->
|
|
def packageTask = (PackageApplication) t2
|
|
def outDir = packageTask.outputDirectory
|
|
def apkNames = packageTask.apkNames
|
|
if (apkNames != null && apkNames.size() > 0) {
|
|
apkNames.forEach { apkName ->
|
|
def apk = new File(outDir, apkName)
|
|
def lp = new File(rootProject.rootDir, "local.properties")
|
|
if (apk.exists() && lp.exists()) {
|
|
def p = new Properties()
|
|
lp.withInputStream { instr ->
|
|
p.load(instr)
|
|
}
|
|
def sdkDir = p.getProperty('sdk.dir')
|
|
def apkSigner = new File(sdkDir, isWindows() ? "build-tools${File.separator}${android.buildToolsVersion}${File.separator}apksigner.bat" : "build-tools${File.separator}${android.buildToolsVersion}${File.separator}apksigner")
|
|
|
|
def newApk = new File(outDir, "normalized_" + apkName)
|
|
def outApk = new File(outDir, "signed_" + apkName)
|
|
def workDir = new File(projectDir, "shell")
|
|
def shell = isMac() ? ".${File.separator}macos${File.separator}ApkNormalized" : (isLinux() ? ".${File.separator}linux64${File.separator}ApkNormalized" : ".${File.separator}windows64${File.separator}ApkNormalized.exe")
|
|
println "***** apk:${apk.name} -> 开始执行apk文件格式对齐 *****"
|
|
ExecResult result = exec {
|
|
workingDir workDir
|
|
commandLine shell, "${apk.absolutePath}", "${newApk.absolutePath}"
|
|
}
|
|
def code = result.exitValue
|
|
if (code == 0) {
|
|
println "***** apk:${apk.name} -> apk文件格式对齐完成 *****"
|
|
}
|
|
|
|
println "***** apk:${newApk.name} -> 对文件格式对齐后的apk重新签名 *****"
|
|
result = exec {
|
|
workingDir apkSigner.parentFile
|
|
commandLine ".${File.separator}${apkSigner.name}", "sign", "-v",
|
|
"--out", "${outApk.absolutePath}",
|
|
"--ks", "${signConfig.storeFile.absolutePath}",
|
|
"--ks-key-alias", "${signConfig.keyAlias}",
|
|
"--ks-pass", "pass:${signConfig.storePassword}",
|
|
"--key-pass", "pass:${signConfig.keyPassword}",
|
|
"--pass-encoding", "utf-8",
|
|
"${newApk.absolutePath}"
|
|
}
|
|
code = result.exitValue
|
|
if (code == 0) {
|
|
println "***** apk:${newApk.name} -> 签名成功 *****"
|
|
}
|
|
println "***** 正在删除临时文件 *****"
|
|
try {
|
|
newApk.delete()
|
|
} catch (Throwable t) {
|
|
t.printStackTrace()
|
|
throw t
|
|
}
|
|
try {
|
|
outApk.renameTo(apk)
|
|
} catch (Throwable t) {
|
|
t.printStackTrace()
|
|
throw t
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static boolean isWindows() {
|
|
return System.getProperty("os.name").toLowerCase().contains('windows')
|
|
}
|
|
|
|
static boolean isLinux() {
|
|
return System.getProperty("os.name").toLowerCase().contains('linux')
|
|
}
|
|
|
|
static boolean isMac() {
|
|
return System.getProperty("os.name").toLowerCase().contains('mac')
|
|
}
|
|
|
|
static boolean isOnlineReleaseBuild(Gradle g) {
|
|
StringBuilder sb = new StringBuilder()
|
|
for (String s : g.startParameter.taskNames) {
|
|
sb.append(s)
|
|
}
|
|
String buildScript = sb.toString().toLowerCase()
|
|
return buildScript.endsWith("release") && buildScript.contains("online")
|
|
}
|
|
|
|
|