import org.apache.tools.ant.filters.FixCrLfFilter import org.apache.tools.ant.filters.ReplaceTokens import java.security.MessageDigest plugins { id('com.android.application') id('dev.rikka.tools.refine') } apply from: file(rootProject.file('module.gradle')) android { namespace "rikka.sui" compileSdk rootProject.ext.targetSdkVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode gitCommitCount versionName moduleVersion.substring(1) //ndkVersion rootProject.ext.ndkVersion } buildFeatures { viewBinding true prefab true } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } buildTypes { debug { defaultConfig.minSdk 24 multiDexEnabled false } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } flavorDimensions "version" productFlavors { riru { dimension "version" externalNativeBuild { cmake { arguments "-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion", "-DRIRU_MODULE_VERSION=$moduleVersionCode", "-DRIRU_MODULE_VERSION_NAME:STRING=\"$moduleVersion\"", "-DFLAVOR=riru", "-DANDROID_STL=none" } } } zygisk { dimension "version" externalNativeBuild { cmake { arguments "-DFLAVOR=zygisk", "-DZYGISK_MODULE_ID:STRING=\"$zygiskModuleId\"", "-DANDROID_STL=none" } } } } lintOptions { checkReleaseBuilds false } dependenciesInfo { includeInApk false } } dependencies { implementation libs.refine.runtime implementation 'dev.rikka.ndk:riru:26.0.0' implementation 'dev.rikka.ndk.thirdparty:cxx:1.2.0' implementation 'dev.rikka.ndk.thirdparty:nativehelper:1.0.1' implementation 'dev.rikka.rikkax.parcelablelist:parcelablelist:2.0.0' implementation "androidx.annotation:annotation:1.3.0" implementation 'androidx.core:core:1.9.0' implementation project(':aidl') implementation project(':shared') implementation project(':api') implementation project(':rish') implementation project(':server-shared') implementation libs.hidden.compat compileOnly libs.hidden.stub } def outDir = file("$rootDir/out") afterEvaluate { def isIDE = properties.containsKey('android.injected.invoked.from.ide') if (isIDE) { println("Invoked from IDE") } else { println("Invoked from command line") } android.applicationVariants.all { variant -> def variantCapped = variant.name.capitalize() def variantLowered = variant.name.toLowerCase() def buildTypeCapped = variant.getBuildType().getName().capitalize() def buildTypeLowered = variant.getBuildType().getName().toLowerCase() def flavorCapped = variantCapped.replaceFirst(buildTypeCapped, "") def flavorLowered = variantLowered.replaceFirst(buildTypeLowered, "") def zipName = "sui-${flavorLowered}-${moduleVersion}-${buildTypeLowered}.zip" def magiskDir = file("$outDir/${flavorLowered}_${buildTypeLowered}") tasks.getByName("pre${variantCapped}Build").dependsOn(":ui:assemble${buildTypeCapped}") task("prepareMagiskFiles${variantCapped}", type: Sync) { dependsOn("assemble$variantCapped") def templatePath = "$rootDir/template/magisk_module" into magiskDir from(templatePath) { exclude 'riru.sh', 'customize.sh', 'post-fs-data.sh', 'module.prop' } if (flavorLowered == 'riru') { from(templatePath) { include 'riru.sh' filter(ReplaceTokens.class, tokens: [ "RIRU_MODULE_LIB_NAME" : moduleLibraryName, "RIRU_MODULE_API_VERSION" : moduleRiruApiVersion.toString(), "RIRU_MODULE_MIN_API_VERSION" : moduleMinRiruApiVersion.toString(), "RIRU_MODULE_MIN_RIRU_VERSION_NAME": moduleMinRiruVersionName, ]) filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) } } from(templatePath) { include 'customize.sh' filter(ReplaceTokens.class, tokens: [ "FLAVOR": flavorLowered, ]) filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) } from(templatePath) { include 'post-fs-data.sh' filter(ReplaceTokens.class, tokens: [ "FLAVOR": flavorLowered, ]) filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) } from(templatePath) { include 'module.prop' expand([ id : (flavorLowered == "zygisk") ? zygiskModuleId : riruModuleId, name : flavorCapped + " - " + moduleName, version : moduleVersion, versionCode: moduleVersionCode.toString(), author : moduleAuthor, description: moduleDescription + " " + ((flavorLowered == "zygisk") ? "This module requires Magisk 24.0+ and Zygisk enabled. DO NOT add SystemUI and Settings to DenyList." : "This module requires Riru $moduleMinRiruVersionName or above."), updateJson : (flavorLowered == "zygisk") ? "https://rikkaapps.github.io/release/sui_zygisk.json" : "https://rikkaapps.github.io/release/sui_riru.json", ]) filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) } from((buildTypeLowered == "release") ? "$buildDir/intermediates/dex/${variant.name}/minify${variantCapped}WithR8" : "$buildDir/intermediates/dex/${variant.name}/mergeDex$variantCapped") { include 'classes.dex' rename { 'sui.dex' } } from("$buildDir/intermediates/stripped_native_libs/${variant.name}/out/lib") { into 'lib' } from("${rootProject.findProject('ui').buildDir}/outputs/apk/$buildTypeLowered") { exclude 'output-metadata.json' rename { 'sui.apk' } } doLast { fileTree("$magiskDir").visit { f -> if (f.directory) return if (f.file.name == '.gitattributes') return def md = MessageDigest.getInstance("SHA-256") f.file.eachByte 4096, { bytes, size -> md.update(bytes, 0, size) } file(f.file.path + ".sha256sum").text = md.digest().encodeHex() } } } task("zip${variantCapped}", type: Zip) { dependsOn("prepareMagiskFiles${variantCapped}") from magiskDir archiveFileName = zipName destinationDirectory = outDir } task("push${variantCapped}", type: Exec) { dependsOn("assemble${variantCapped}") workingDir outDir commandLine android.adbExecutable, "push", zipName, "/data/local/tmp/" } task("flash${variantCapped}", type: Exec) { dependsOn("push${variantCapped}") commandLine android.adbExecutable, "shell", "su", "-c", "magisk --install-module /data/local/tmp/${zipName}" } task("flashAndReboot${variantCapped}", type: Exec) { dependsOn("flash${variantCapped}") commandLine android.adbExecutable, "shell", "reboot" } variant.assembleProvider.get().finalizedBy("zip${variantCapped}") } }