mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 12:05:30 +00:00
Fix gradle build cache
This commit is contained in:
parent
9b1e173373
commit
c1909d520b
@ -73,8 +73,6 @@ fun genKeyData(keysDir: File, outSrc: File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun genStubManifest(srcDir: File, outDir: File): String {
|
fun genStubManifest(srcDir: File, outDir: File): String {
|
||||||
outDir.deleteRecursively()
|
|
||||||
|
|
||||||
fun String.ind(level: Int) = replaceIndentByMargin(" ".repeat(level))
|
fun String.ind(level: Int) = replaceIndentByMargin(" ".repeat(level))
|
||||||
|
|
||||||
val cmpList = mutableListOf<String>()
|
val cmpList = mutableListOf<String>()
|
||||||
|
@ -134,6 +134,7 @@ private fun Project.setupAppCommon() {
|
|||||||
|
|
||||||
lint {
|
lint {
|
||||||
disable += "MissingTranslation"
|
disable += "MissingTranslation"
|
||||||
|
checkReleaseBuilds = false
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesInfo {
|
dependenciesInfo {
|
||||||
@ -193,7 +194,6 @@ fun Project.setupApp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val syncResources by tasks.registering(Sync::class) {
|
val syncResources by tasks.registering(Sync::class) {
|
||||||
dependsOn(syncLibs)
|
|
||||||
into("src/main/resources/META-INF/com/google/android")
|
into("src/main/resources/META-INF/com/google/android")
|
||||||
from(rootProject.file("scripts/update_binary.sh")) {
|
from(rootProject.file("scripts/update_binary.sh")) {
|
||||||
rename { "update-binary" }
|
rename { "update-binary" }
|
||||||
@ -206,13 +206,16 @@ fun Project.setupApp() {
|
|||||||
android.applicationVariants.all {
|
android.applicationVariants.all {
|
||||||
val variantCapped = name.replaceFirstChar { it.uppercase() }
|
val variantCapped = name.replaceFirstChar { it.uppercase() }
|
||||||
|
|
||||||
|
tasks.getByPath("merge${variantCapped}JniLibFolders").dependsOn(syncLibs)
|
||||||
|
processJavaResourcesProvider.configure { dependsOn(syncResources) }
|
||||||
|
|
||||||
val stubTask = tasks.getByPath(":stub:package$variantCapped")
|
val stubTask = tasks.getByPath(":stub:package$variantCapped")
|
||||||
val stubApk = stubTask.outputs.files.asFileTree.filter {
|
val stubApk = stubTask.outputs.files.asFileTree.filter {
|
||||||
it.name.endsWith(".apk")
|
it.name.endsWith(".apk")
|
||||||
}
|
}
|
||||||
|
|
||||||
val syncAssets = tasks.register("sync${variantCapped}Assets", Sync::class) {
|
val syncAssets = tasks.register("sync${variantCapped}Assets", Sync::class) {
|
||||||
dependsOn(syncResources, stubTask)
|
dependsOn(stubTask)
|
||||||
inputs.property("version", Config.version)
|
inputs.property("version", Config.version)
|
||||||
inputs.property("versionCode", Config.versionCode)
|
inputs.property("versionCode", Config.versionCode)
|
||||||
into("src/main/assets")
|
into("src/main/assets")
|
||||||
@ -240,8 +243,7 @@ fun Project.setupApp() {
|
|||||||
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mergeAssetsProvider.configure { dependsOn(syncAssets) }
|
||||||
preBuildProvider.get().dependsOn(syncAssets)
|
|
||||||
|
|
||||||
val keysDir = rootProject.file("tools/keys")
|
val keysDir = rootProject.file("tools/keys")
|
||||||
val outSrcDir = File(buildDir, "generated/source/keydata/$name")
|
val outSrcDir = File(buildDir, "generated/source/keydata/$name")
|
||||||
@ -265,7 +267,8 @@ fun Project.setupStub() {
|
|||||||
val variantCapped = name.replaceFirstChar { it.uppercase() }
|
val variantCapped = name.replaceFirstChar { it.uppercase() }
|
||||||
val variantLowered = name.lowercase()
|
val variantLowered = name.lowercase()
|
||||||
val manifest = file("src/${variantLowered}/AndroidManifest.xml")
|
val manifest = file("src/${variantLowered}/AndroidManifest.xml")
|
||||||
val outSrcDir = File(buildDir, "generated/source/obfuscate/${variantLowered}")
|
val outManifestDir = File(buildDir, "generated/source/manifest/${variantLowered}")
|
||||||
|
val outResDir = File(buildDir, "generated/source/res/${variantLowered}")
|
||||||
val templateDir = file("template")
|
val templateDir = file("template")
|
||||||
val aapt = File(android.sdkDirectory, "build-tools/${android.buildToolsVersion}/aapt2")
|
val aapt = File(android.sdkDirectory, "build-tools/${android.buildToolsVersion}/aapt2")
|
||||||
val apk = File(buildDir, "intermediates/processed_res/" +
|
val apk = File(buildDir, "intermediates/processed_res/" +
|
||||||
@ -273,51 +276,52 @@ fun Project.setupStub() {
|
|||||||
val apkTmp = File("${apk}.tmp")
|
val apkTmp = File("${apk}.tmp")
|
||||||
|
|
||||||
val genManifestTask = tasks.register("generate${variantCapped}ObfuscatedManifest") {
|
val genManifestTask = tasks.register("generate${variantCapped}ObfuscatedManifest") {
|
||||||
|
inputs.property("seed", RAND_SEED)
|
||||||
|
inputs.dir(templateDir)
|
||||||
|
outputs.dir(outManifestDir)
|
||||||
|
outputs.file(manifest)
|
||||||
doLast {
|
doLast {
|
||||||
val xml = genStubManifest(templateDir, outSrcDir)
|
val xml = genStubManifest(templateDir, outManifestDir)
|
||||||
manifest.parentFile.mkdirs()
|
manifest.parentFile.mkdirs()
|
||||||
PrintStream(manifest).use {
|
PrintStream(manifest).use {
|
||||||
it.print(xml)
|
it.print(xml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.getByPath(":stub:process${variantCapped}MainManifest").dependsOn(genManifestTask)
|
preBuildProvider.configure { dependsOn(genManifestTask) }
|
||||||
|
registerJavaGeneratingTask(genManifestTask, outManifestDir)
|
||||||
|
|
||||||
val genSrcTask = tasks.register("generate${variantCapped}ObfuscatedSources") {
|
val processResourcesTask = tasks.getByPath(":stub:process${variantCapped}Resources")
|
||||||
dependsOn(":stub:process${variantCapped}Resources")
|
processResourcesTask.doLast {
|
||||||
inputs.file(apk)
|
exec {
|
||||||
outputs.file(apk)
|
commandLine(aapt, "optimize", "-o", apkTmp, "--collapse-resource-names", apk)
|
||||||
doLast {
|
|
||||||
exec {
|
|
||||||
commandLine(aapt, "optimize", "-o", apkTmp, "--collapse-resource-names", apk)
|
|
||||||
}
|
|
||||||
|
|
||||||
val bos = ByteArrayOutputStream()
|
|
||||||
ZipFile(apkTmp).use { src ->
|
|
||||||
ZipOutputStream(apk.outputStream()).use {
|
|
||||||
it.setLevel(Deflater.BEST_COMPRESSION)
|
|
||||||
it.putNextEntry(ZipEntry("AndroidManifest.xml"))
|
|
||||||
src.getInputStream(src.getEntry("AndroidManifest.xml")).transferTo(it)
|
|
||||||
it.closeEntry()
|
|
||||||
}
|
|
||||||
DeflaterOutputStream(bos, Deflater(Deflater.BEST_COMPRESSION)).use {
|
|
||||||
src.getInputStream(src.getEntry("resources.arsc")).transferTo(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apkTmp.delete()
|
|
||||||
genEncryptedResources(ByteArrayInputStream(bos.toByteArray()), outSrcDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val bos = ByteArrayOutputStream()
|
||||||
|
ZipFile(apkTmp).use { src ->
|
||||||
|
ZipOutputStream(apk.outputStream()).use {
|
||||||
|
it.setLevel(Deflater.BEST_COMPRESSION)
|
||||||
|
it.putNextEntry(ZipEntry("AndroidManifest.xml"))
|
||||||
|
src.getInputStream(src.getEntry("AndroidManifest.xml")).transferTo(it)
|
||||||
|
it.closeEntry()
|
||||||
|
}
|
||||||
|
DeflaterOutputStream(bos, Deflater(Deflater.BEST_COMPRESSION)).use {
|
||||||
|
src.getInputStream(src.getEntry("resources.arsc")).transferTo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apkTmp.delete()
|
||||||
|
genEncryptedResources(ByteArrayInputStream(bos.toByteArray()), outResDir)
|
||||||
}
|
}
|
||||||
registerJavaGeneratingTask(genSrcTask, outSrcDir)
|
@Suppress("DEPRECATION")
|
||||||
|
registerJavaGeneratingTask(processResourcesTask, outResDir)
|
||||||
}
|
}
|
||||||
// Override optimizeReleaseResources task
|
// Override optimizeReleaseResources task
|
||||||
|
val apk = File(buildDir, "intermediates/processed_res/" +
|
||||||
|
"release/out/resources-release.ap_")
|
||||||
|
val optRes = File(buildDir, "intermediates/optimized_processed_res/" +
|
||||||
|
"release/resources-release-optimize.ap_")
|
||||||
tasks.whenTaskAdded {
|
tasks.whenTaskAdded {
|
||||||
if (name == "optimizeReleaseResources") {
|
if (name == "optimizeReleaseResources") {
|
||||||
dependsOn("generateReleaseObfuscatedSources")
|
|
||||||
val apk = File(buildDir, "intermediates/processed_res/" +
|
|
||||||
"release/out/resources-release.ap_")
|
|
||||||
val optRes = File(buildDir, "intermediates/optimized_processed_res/" +
|
|
||||||
"release/resources-release-optimize.ap_")
|
|
||||||
doLast { apk.copyTo(optRes, true) }
|
doLast { apk.copyTo(optRes, true) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user