LSPosed/edxp-core/build.gradle

267 lines
10 KiB
Groovy

import org.apache.tools.ant.filters.FixCrLfFilter
import org.gradle.internal.os.OperatingSystem
import java.security.MessageDigest
apply plugin: 'com.android.library'
static def calcSha256(file) {
def md = MessageDigest.getInstance("SHA-256")
file.eachByte 4096, { bytes, size ->
md.update(bytes, 0, size);
}
return md.digest().encodeHex()
}
// Values set here will be overriden by AppVeyor, feel free to modify during development.
def buildVersionName = 'v0.5.1.0'
def buildVersionCode = 233
if (System.env.APPVEYOR_BUILD_VERSION != null) {
buildVersionName = "v${System.getenv('appveyor_build_version')}"
}
if (System.env.APPVEYOR_BUILD_NUMBER != null) {
// Split is necessary because PRs set the build number to "1234-something".
def parts = System.env.APPVEYOR_BUILD_NUMBER.split('-')
buildVersionCode = Integer.valueOf(parts[0])
}
version buildVersionName
ext {
versionCode = buildVersionCode
module_name = "EdXposed"
jar_dest_dir = "${projectDir}/template_override/system/framework/"
is_windows = OperatingSystem.current().isWindows()
backends = ["YAHFA", "SandHook"]
yahfa_module_id = "riru_edxposed"
sandhook_module_id = yahfa_module_id + "_sandhook"
yahfa_authors = "solohsu, MlgmXyysd & rk700"
sandhook_authors = "solohsu, MlgmXyysd & ganyao114"
riruModuleId = "edxp"
moduleMinRiruApiVersion = 10
moduleMinRiruVersionName = "v23.0"
moduleMaxRiruApiVersion = 10
}
repositories {
mavenLocal()
jcenter()
maven { url 'https://dl.bintray.com/rikkaw/Libraries' }
}
dependencies {
implementation 'rikka.ndk:riru:10'
}
android {
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
minSdkVersion androidMinSdkVersion.toInteger()
targetSdkVersion androidTargetSdkVersion.toInteger()
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
cppFlags "-std=c++17 -ffixed-x18 -Qunused-arguments -frtti -fomit-frame-pointer"
cFlags "-std=gnu99 -ffixed-x18 -Qunused-arguments -frtti -fomit-frame-pointer"
arguments "-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
"-DRIRU_MODULE_VERSION=$buildVersionCode",
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$buildVersionName\""
}
}
}
buildTypes {
debug {
externalNativeBuild {
cmake {
cppFlags "-O0"
cFlags "-O0"
}
}
}
release {
externalNativeBuild {
cmake {
cppFlags "-fvisibility=hidden -fvisibility-inlines-hidden -O2 -s -Wno-unused-value -fomit-frame-pointer"
cFlags "-fvisibility=hidden -fvisibility-inlines-hidden -O2 -s -Wno-unused-value -fomit-frame-pointer"
}
}
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
ndkVersion androidCompileNdkVersion
}
task cleanTemplate(type: Delete) {
delete file(templateSystemx86Path)
}
afterEvaluate {
android.libraryVariants.all { variant ->
def variantCapped = variant.name.capitalize()
def variantLowered = variant.name.toLowerCase()
backends.each { backend ->
def backendLowered = backend.toLowerCase()
def backendCapped = backendLowered.capitalize()
def authorList = property("${backendLowered}" + "_authors")
def magiskModuleId = property("${backendLowered}" + "_module_id")
delete file(zipPathMagiskReleasePath)
def prepareJarsTask = task("prepareJars${backendCapped}${variantCapped}") {
dependsOn cleanTemplate
dependsOn tasks.getByPath(":dexmaker:copyDex${variantCapped}")
dependsOn tasks.getByPath(":dalvikdx:copyDex${variantCapped}")
dependsOn tasks.getByPath(":edxp-service:copyDex${variantCapped}")
dependsOn tasks.getByPath(":edxp-${backendLowered}:copyDex${variantCapped}")
}
def prepareMagiskFilesTask = task("prepareMagiskFiles${backendCapped}${variantCapped}", type: Delete) {
dependsOn prepareJarsTask, "assemble${variantCapped}"
doFirst {
copy {
from "${projectDir}/tpl/edconfig.tpl"
into templateFrameworkPath
rename "edconfig.tpl", "edconfig.jar"
expand(version: "$version", backend: "$backend", apiCode: "$apiCode")
}
copy {
from "${projectDir}/tpl/module.prop.tpl"
into templateRootPath
rename "module.prop.tpl", "module.prop"
expand(moduleId: "$magiskModuleId", backend: "$backendCapped",
versionName: "$version" + " ($backend)",
versionCode: "$versionCode", authorList: "$authorList",
apiCode: "$apiCode")
filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
copy {
from "${projectDir}/tpl/riru_module.prop.tpl"
into "$templateRootPath/riru"
rename "riru_module.prop.tpl", "module.prop.new"
expand(minApi: "$moduleMinRiruApiVersion",
versionName: "$version" + " ($backend)",
versionCode: "$versionCode", authorList: "$authorList")
filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
}
def libPathRelease = "${buildDir}/intermediates/cmake/${variantLowered}/obj"
def exclude_list = ["riru.sh"]
doLast {
copy {
from "${projectDir}/template_override"
into zipPathMagiskReleasePath
exclude exclude_list
}
copy {
from "${projectDir}/template_override"
into zipPathMagiskReleasePath
include 'riru.sh'
filter { line ->
line.replaceAll('%%%RIRU_MODULE_ID%%%', riruModuleId)
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', moduleMinRiruApiVersion.toString())
.replaceAll('%%%RIRU_MIN_VERSION_NAME%%%', moduleMinRiruVersionName)
}
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
copy {
include "libriru_edxp.so"
from "$libPathRelease/armeabi-v7a"
into "$zipPathMagiskReleasePath/system/lib"
}
copy {
include "libriru_edxp.so"
from "$libPathRelease/arm64-v8a"
into "$zipPathMagiskReleasePath/system/lib64"
}
copy {
include "libriru_edxp.so"
from "$libPathRelease/x86"
into "$zipPathMagiskReleasePath/system_x86/lib"
}
copy {
include "libriru_edxp.so"
from "$libPathRelease/x86_64"
into "$zipPathMagiskReleasePath/system_x86/lib64"
}
// generate sha1sum
fileTree(zipPathMagiskReleasePath).matching {
exclude "README.md", "META-INF"
}.visit { f ->
if (f.directory) return
file(f.file.path + ".sha256sum").text = calcSha256(f.file)
}
}
}
def zipTask = task("zip${backendCapped}${variantCapped}", type: Zip) {
dependsOn prepareMagiskFilesTask
archiveName "${module_name}-${backend}-${project.version}-${variantLowered}.zip"
destinationDir file("$projectDir/release")
from "$zipPathMagiskReleasePath"
}
task("push${backendCapped}${variantCapped}", type: Exec) {
dependsOn zipTask
workingDir "${projectDir}/release"
def commands = [android.adbExecutable, "push",
"${module_name}-${backend}-${project.version}-${variantLowered}.zip",
"/data/local/tmp/"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
task("flash${backendCapped}${variantCapped}", type: Exec) {
dependsOn tasks.getByPath("push${backendCapped}${variantCapped}")
workingDir "${projectDir}/release"
def commands = [android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${module_name}-${backend}-${project.version}-${variantLowered}.zip"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
task("flashAndReboot${backendCapped}${variantCapped}", type: Exec) {
dependsOn tasks.getByPath("flash${backendCapped}${variantCapped}")
workingDir "${projectDir}/release"
def commands = [android.adbExecutable, "shell", "reboot"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
}
// backward compatible
task("zip${variantCapped}") {
dependsOn "zipYahfa${variantCapped}"
}
task("push${variantCapped}") {
dependsOn "pushYahfa${variantCapped}"
}
}
}