mirror of
https://github.com/chiteroman/TrickyStore.git
synced 2025-07-17 15:29:32 +00:00
Initial commit
This commit is contained in:
154
module/build.gradle.kts
Normal file
154
module/build.gradle.kts
Normal file
@@ -0,0 +1,154 @@
|
||||
import android.databinding.tool.ext.capitalizeUS
|
||||
import org.apache.tools.ant.filters.FixCrLfFilter
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
import java.security.MessageDigest
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.agp.app)
|
||||
}
|
||||
|
||||
val moduleId: String by rootProject.extra
|
||||
val moduleName: String by rootProject.extra
|
||||
val verCode: Int by rootProject.extra
|
||||
val verName: String by rootProject.extra
|
||||
val commitHash: String by rootProject.extra
|
||||
val abiList: List<String> by rootProject.extra
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
ndk {
|
||||
abiFilters.addAll(abiList)
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cppFlags("-std=c++20")
|
||||
arguments(
|
||||
"-DANDROID_STL=none",
|
||||
"-DMODULE_NAME=$moduleId"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path("src/main/cpp/CMakeLists.txt")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
androidComponents.onVariants { variant ->
|
||||
afterEvaluate {
|
||||
val variantLowered = variant.name.lowercase()
|
||||
val variantCapped = variant.name.capitalizeUS()
|
||||
val buildTypeLowered = variant.buildType?.lowercase()
|
||||
val supportedAbis = abiList.map {
|
||||
when (it) {
|
||||
"arm64-v8a" -> "arm64"
|
||||
"armeabi-v7a" -> "arm"
|
||||
"x86" -> "x86"
|
||||
"x86_64" -> "x64"
|
||||
else -> error("unsupported abi $it")
|
||||
}
|
||||
}.joinToString(" ")
|
||||
|
||||
val moduleDir = layout.buildDirectory.file("outputs/module/$variantLowered")
|
||||
val zipFileName =
|
||||
"$moduleName-$verName-$verCode-$commitHash-$buildTypeLowered.zip".replace(' ', '-')
|
||||
|
||||
val prepareModuleFilesTask = task<Sync>("prepareModuleFiles$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn("assemble$variantCapped")
|
||||
into(moduleDir)
|
||||
from(rootProject.layout.projectDirectory.file("README.md"))
|
||||
from(layout.projectDirectory.file("template")) {
|
||||
exclude("module.prop", "customize.sh", "post-fs-data.sh", "service.sh")
|
||||
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
from(layout.projectDirectory.file("template")) {
|
||||
include("module.prop")
|
||||
expand(
|
||||
"moduleId" to moduleId,
|
||||
"moduleName" to moduleName,
|
||||
"versionName" to "$verName ($verCode-$commitHash-$variantLowered)",
|
||||
"versionCode" to verCode
|
||||
)
|
||||
}
|
||||
from(layout.projectDirectory.file("template")) {
|
||||
include("customize.sh", "post-fs-data.sh", "service.sh")
|
||||
val tokens = mapOf(
|
||||
"DEBUG" to if (buildTypeLowered == "debug") "true" else "false",
|
||||
"SONAME" to moduleId,
|
||||
"SUPPORTED_ABIS" to supportedAbis
|
||||
)
|
||||
filter<ReplaceTokens>("tokens" to tokens)
|
||||
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
from(layout.buildDirectory.file("intermediates/stripped_native_libs/$variantLowered/strip${variantCapped}DebugSymbols/out/lib")) {
|
||||
into("lib")
|
||||
}
|
||||
|
||||
doLast {
|
||||
fileTree(moduleDir).visit {
|
||||
if (isDirectory) return@visit
|
||||
val md = MessageDigest.getInstance("SHA-256")
|
||||
file.forEachBlock(4096) { bytes, size ->
|
||||
md.update(bytes, 0, size)
|
||||
}
|
||||
file(file.path + ".sha256").writeText(
|
||||
org.apache.commons.codec.binary.Hex.encodeHexString(
|
||||
md.digest()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val zipTask = task<Zip>("zip$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(prepareModuleFilesTask)
|
||||
archiveFileName.set(zipFileName)
|
||||
destinationDirectory.set(layout.projectDirectory.file("release").asFile)
|
||||
from(moduleDir)
|
||||
}
|
||||
|
||||
val pushTask = task<Exec>("push$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(zipTask)
|
||||
commandLine("adb", "push", zipTask.outputs.files.singleFile.path, "/data/local/tmp")
|
||||
}
|
||||
|
||||
val installKsuTask = task<Exec>("installKsu$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(pushTask)
|
||||
commandLine(
|
||||
"adb", "shell", "su", "-c",
|
||||
"/data/adb/ksud module install /data/local/tmp/$zipFileName"
|
||||
)
|
||||
}
|
||||
|
||||
val installMagiskTask = task<Exec>("installMagisk$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(pushTask)
|
||||
commandLine(
|
||||
"adb",
|
||||
"shell",
|
||||
"su",
|
||||
"-M",
|
||||
"-c",
|
||||
"magisk --install-module /data/local/tmp/$zipFileName"
|
||||
)
|
||||
}
|
||||
|
||||
task<Exec>("installKsuAndReboot$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(installKsuTask)
|
||||
commandLine("adb", "reboot")
|
||||
}
|
||||
|
||||
task<Exec>("installMagiskAndReboot$variantCapped") {
|
||||
group = "module"
|
||||
dependsOn(installMagiskTask)
|
||||
commandLine("adb", "reboot")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user