version:1.0.6

fix:
update:mdm功能对接,增加gradle自动嵌入证书并签名
This commit is contained in:
2026-01-19 09:52:39 +08:00
parent 38c0e22737
commit fb7c1138df
95 changed files with 9463 additions and 442 deletions

View File

@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
def appName() {
return "XwadOS"
return "XwadOSHonor"
}
def releaseTime() {
@@ -17,8 +17,8 @@ android {
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
versionCode 7
versionName "1.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -83,6 +83,79 @@ android {
}
// def cerFile = file("E:\\Xuewang365\\HonorCer\\HONOR.CER")
applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
// 建议使用 packageApplication 任务,它更明确指向 APK 生成
def packageTask = tasks.findByName("package${variantName}")
if (packageTask) {
packageTask.doLast {
// 1. 配置路径优化:尽量使用 project 属性,避免写死 E:\ 盘符
def cerFile = file("E:\\Xuewang365\\HonorCer\\HONOR.CER")
if (!cerFile.exists()) {
println "⚠️ 未找到证书文件: ${cerFile.path}"
return
}
def sdkDir = android.sdkDirectory.path
// def buildToolsVersion = android.buildToolsVersion // 建议动态获取,除非有特定版本要求
def buildToolsVersion = "33.0.0"
def buildToolsPath = "${sdkDir}/build-tools/${buildToolsVersion}"
def aaptPath = "${buildToolsPath}/aapt${org.gradle.internal.os.OperatingSystem.current().isWindows() ? '.exe' : ''}"
def apksignerPath = "${buildToolsPath}/apksigner${org.gradle.internal.os.OperatingSystem.current().isWindows() ? '.bat' : ''}"
// 2. 关键优化:精准定位当前 Variant 的输出文件
// 使用 variant.outputs 获取当前构建生成的特定文件
variant.outputs.all { output ->
def apkFile = output.outputFile
println "APK地址:${apkFile.absolutePath}"
if (apkFile != null && apkFile.name.endsWith(".apk")) {
println "🛠️ 开始对当前 APK 注入: ${apkFile.name}"
// 3. 准备 META-INF 临时结构
def tempBaseDir = new File(project.buildDir, "intermediates/honor_cer_temp/${variant.name}")
def metaInfDir = new File(tempBaseDir, "META-INF")
metaInfDir.deleteDir() // 清理旧数据
metaInfDir.mkdirs()
def targetFile = new File(metaInfDir, cerFile.name)
ant.copy(file: cerFile, tofile: targetFile)
// 4. 调用 aapt 注入
exec {
workingDir tempBaseDir
commandLine aaptPath, "add", apkFile.absolutePath, "META-INF/${cerFile.name}"
}
// 5. 重新签名 (Apksigner)
def signingConfig = variant.signingConfig
if (signingConfig != null && signingConfig.storeFile.exists()) {
exec {
commandLine apksignerPath, "sign",
"--ks", signingConfig.storeFile.absolutePath,
"--ks-pass", "pass:${signingConfig.storePassword}",
"--ks-key-alias", signingConfig.keyAlias,
"--key-pass", "pass:${signingConfig.keyPassword}",
"--v2-signing-enabled", "true",
"--v3-signing-enabled", "true",
apkFile.path
}
println "✅ [${variant.name}] 注入并修复签名成功!"
} else {
println "❌ [${variant.name}] 签名失败SigningConfig 配置无效"
}
// 清理临时目录
tempBaseDir.deleteDir()
}
}
}
}
}
buildTypes {
debug {
@@ -90,7 +163,7 @@ android {
minifyEnabled false
//Zipalign优化
zipAlignEnabled true
buildConfigField "String", "platform", '"tuixin"'
buildConfigField "String", "platform", '"HONOR"'
signingConfig signingConfigs.tuixin
applicationVariants.all { variant ->
variant.outputs.each { output ->
@@ -111,7 +184,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//签名
signingConfig signingConfigs.tuixin
buildConfigField "String", "platform", '"tuixin"'
buildConfigField "String", "platform", '"HONOR"'
// 将release版本的包名重命名加上版本及日期
applicationVariants.all { variant ->
variant.outputs.each { output ->
@@ -126,6 +199,7 @@ android {
}
}
}
dependencies {