Skip to content

Commit

Permalink
Add push, flash, flashAndReboot task for build.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Mar 22, 2021
1 parent 91204fc commit 27d4506
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@ In conclusion, we can get a superuser interface similar to standard Android APIs

## Build

* Clone with `git clone --recurse-submodules`
* Run gradle task `:module:assembleRelease` task from Android Studio or the terminal, zip will be saved to `out`
Clone with `git clone --recurse-submodules`.

Gradle tasks:

* `:riru:assembleDebug/Release`

Generate Magisk module zip to `out`.

* `:riru:pushDebug/Release`

Push the zip with adb to `/data/local/tmp`.

* `:riru:flashDebug/Release`

Flash the zip with `adb shell su -c magisk --install-module`.

* `:riru:flashAndRebootDebug/Release`

Flash the zip and reboot the device.

## Guide for users

Expand Down
9 changes: 5 additions & 4 deletions module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ ext {
gitCommitId = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
gitCommitCount = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim())

moduleMinRiruApiVersion = 25
moduleMinRiruVersionName = "v25.0.0"
moduleRiruApiVersion = 25

moduleId = "sui"
moduleName = "Sui"
moduleAuthor = "Rikka"
moduleDescription = "Modern superuser interface implementation, shares the same API design from Shizuku."
moduleDescription = "Modern superuser interface implementation, shares the same API design from Shizuku. This modules requires Riru $moduleMinRiruVersionName or above."
moduleVersionMinor = 6
moduleVersionPatch = 0
moduleVersion = "v${api_version_major}.${moduleVersionMinor}.${moduleVersionPatch}"
moduleVersionCode = gitCommitCount
moduleMinRiruApiVersion = 24
moduleMinRiruVersionName = "v24.0.0"
moduleRiruApiVersion = 25

moduleProp = [
id : "riru-${moduleId.replace('_', '-')}",
Expand Down
58 changes: 45 additions & 13 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ static def calcSha256(file) {
}

android.applicationVariants.all { variant ->
def variantCapped = variant.name.capitalize()
def variantLowered = variant.name.toLowerCase()

def zipName = "${moduleId}-${moduleVersion}-${variantLowered}.zip"

def is_windows = org.gradle.internal.os.OperatingSystem.current().isWindows()

task ("zip${variantCapped}", type: Zip) {
dependsOn("assemble${variantCapped}")
from magiskDir
archiveName zipName
destinationDir outDir
}

variant.outputs.all {
def task = variant.assembleProvider.get()
task.doLast {
Expand Down Expand Up @@ -176,22 +190,40 @@ android.applicationVariants.all { variant ->
file(f.file.path + ".sha256sum").text = calcSha256(f.file)
}
}
if (variant.buildType.name == "debug") {
task.finalizedBy zipMagiskMoudleDebug
task.finalizedBy("zip${variantCapped}")
}

task ("push${variantCapped}", type: Exec) {
dependsOn("assemble${variantCapped}")
workingDir outDir
def commands = [android.adbExecutable, "push",
zipName,
"/data/local/tmp/"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
task.finalizedBy zipMagiskMoudleRelease
commandLine commands
}
}
}

task zipMagiskMoudleRelease(type: Zip) {
from magiskDir
archiveName "riru-${moduleId}-${moduleVersion}-release.zip"
destinationDir outDir
}
task("flash${variantCapped}", type: Exec) {
dependsOn("push${variantCapped}")
def commands = [android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${zipName}"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}

task zipMagiskMoudleDebug(type: Zip) {
from magiskDir
archiveName "riru-${moduleId}-${moduleVersion}-debug.zip"
destinationDir outDir
task("flashAndReoot${variantCapped}", type: Exec) {
dependsOn("flash${variantCapped}")
def commands = [android.adbExecutable, "shell", "reboot"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
}

0 comments on commit 27d4506

Please sign in to comment.