import org.apache.tools.ant.filters.FixCrLfFilter import org.gradle.internal.os.OperatingSystem apply plugin: 'com.android.library' version "v0.4.2.3_beta" ext { versionCode = "4230" module_name = "EdXposed" jar_dest_dir = "${projectDir}/template_override/system/framework/" is_windows = OperatingSystem.current().isWindows() backends = ["YAHFA", "SandHook", "Whale"] yahfa_module_id = "riru_edxposed" sandhook_module_id = yahfa_module_id + "_sandhook" whale_module_id = yahfa_module_id + "_whale" yahfa_authors = "solohsu, rk700 & MlgmXyysd" sandhook_authors = "solohsu, ganyao114 & MlgmXyysd" whale_authors = "solohsu, asLody & MlgmXyysd" riruModuleId = "edxp" libPathRelease = "$buildDir/ndkBuild/release/lib" zipPathMagiskRelease = "$buildDir/tmp/release/magisk" } android { compileSdkVersion 28 defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion externalNativeBuild { ndkBuild { abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64' arguments "NDK_PROJECT_PATH=jni/" } } } externalNativeBuild { ndkBuild { path 'jni/Android.mk' } } } task copyDalvikdxJar { def jarTask = tasks.getByPath(':dalvikdx:dexInJar') dependsOn jarTask doLast { copy { from jarTask into jar_dest_dir } } onlyIf { !jarTask.state.upToDate || !file(jar_dest_dir + jarTask.archiveName).exists() } } task copyDexmakerJar { def jarTask = tasks.getByPath(':dexmaker:dexInJar') dependsOn jarTask doLast { copy { from jarTask into jar_dest_dir } } onlyIf { !jarTask.state.upToDate || !file(jar_dest_dir + jarTask.archiveName).exists() } } task cleanTemplate(type: Delete) { delete file(templateSystemPath), file(templateSystemx86Path) } // riru related tasks task buildNativeRelease(type: Exec) { if (is_windows) commandLine 'cmd', '/c', 'ndk-build.cmd', '-j8', "NDK_LIBS_OUT=$libPathRelease", "NDK_OUT=$buildDir/ndkBuild/release/obj".replace("\\", "/") else commandLine 'ndk-build', '-j8', "NDK_LIBS_OUT=$libPathRelease", "NDK_OUT=$buildDir/ndkBuild/release/obj" } task cleanMagiskRelease(type: Delete) { delete file(zipPathMagiskRelease) } task copyFilesMagiskRelease { doLast { copy { from "${projectDir}/template_override" into zipPathMagiskRelease } copy { from 'template_override/riru_module.prop' into "$zipPathMagiskRelease/data/misc/riru/modules/${riruModuleId}" } copy { from "$libPathRelease/armeabi-v7a" into "$zipPathMagiskRelease/system/lib" } copy { from "$libPathRelease/arm64-v8a" into "$zipPathMagiskRelease/system/lib64" } copy { from "$libPathRelease/x86" into "$zipPathMagiskRelease/system_x86/lib" } copy { from "$libPathRelease/x86_64" into "$zipPathMagiskRelease/system_x86/lib64" } file("$zipPathMagiskRelease/riru_module.prop").delete() file("$zipPathMagiskRelease/data/misc/riru/modules/${riruModuleId}/riru_module.prop").renameTo("$zipPathMagiskRelease/data/misc/riru/modules/${riruModuleId}/module.prop") } } 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") def prepareJarsTask = task("prepareJars${backendCapped}${variantCapped}") { dependsOn cleanTemplate, copyDalvikdxJar, copyDexmakerJar dependsOn tasks.getByPath(":edxp-${backendLowered}:makeAndCopy${variantCapped}") } def preZipTask = task("preZip${backendCapped}${variantCapped}", type: GradleBuild) { dependsOn prepareJarsTask tasks = [ 'buildNativeRelease', 'cleanMagiskRelease', 'copyFilesMagiskRelease' ] doFirst { copy { from "${projectDir}/tpl/edconfig.tpl" into templateFrameworkPath rename "edconfig.tpl", "edconfig.jar" expand(version: "$version", backend: "$backend") } 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") filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) } copy { from "${templateRootPath}/module.prop" into templateRootPath rename "module.prop", "riru_module.prop" } } } def zipTask = task("zip${backendCapped}${variantCapped}", type: Zip) { dependsOn preZipTask archiveName "magisk-${module_name}-${backend}-${project.version}-${variantLowered}.zip" destinationDir file("$projectDir/release") from "$zipPathMagiskRelease" } task("push${backendCapped}${variantCapped}", type: Exec) { dependsOn zipTask workingDir "${projectDir}/release" def commands = ["adb", "push", "magisk-${module_name}-${backend}-${project.version}-${variantLowered}.zip", "/sdcard/"] 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}" } } }