Skip to content

Commit

Permalink
Using relative Gradle path as to more easily include the project in o…
Browse files Browse the repository at this point in the history
…ther Gradle projects + fixing gradle tasks
  • Loading branch information
Alhyoss committed Oct 18, 2022
1 parent b54a335 commit e7f2924
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 29 deletions.
53 changes: 26 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ext {
riruApiVersion = 26
riruMinApiVersion = 24

repo = new FileRepository(rootProject.file(".git"))
repo = new FileRepository(file(".git"))
gitObjectId = repo.refDatabase.exactRef("refs/remotes/origin/master").objectId
gitCommitId = gitObjectId.abbreviate(10).name()
gitCommitCount = StreamSupport.stream(new Git(repo).log().add(gitObjectId).call().spliterator(), false).count()
Expand All @@ -45,71 +45,70 @@ ext {
riruVersionName = "${riruVersionNameShort}.r${gitCommitCount}.${gitCommitId}"
riruVersionCode = gitCommitCount

outDir = file("$rootDir/out")
outDir = file("out")

riruPath = "/riru"
}

def getProject(String name) {
return project(name)
}

task clean(type: Delete) {
delete rootProject.buildDir, outDir
delete buildDir, outDir
}

["Release", "Debug"].forEach { variant ->
def zipName = "riru-${riruVersionName}-${variant}.zip"
def flashDir = file("$outDir/riru-${riruVersionName}-${variant}")

task("prepareUpdateFiles${variant}") {
dependsOn("clean")
dependsOn(":rirud:assemble$variant")
dependsOn(":riru:assemble$variant")
dependsOn("rirud:assemble$variant")
dependsOn("riru:assemble$variant")

doLast {
def templatePath = "$rootDir/template/update_package"
def templatePath = "template/update_package"
copy {
into flashDir
from(templatePath) {
exclude 'update.sh', 'files/rirud_launcher.rc'
exclude 'zip/update.sh', 'zip/files/rirud_launcher.rc'
}
from(templatePath) {
include 'update.sh', 'files/rirud_launcher.rc'
include 'zip/update.sh', 'zip/files/rirud_launcher.rc'
filter(ReplaceTokens.class, tokens: [
"RIRU_PATH": riruPath.toString()
])
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
from(project(":riru").buildDir.absolutePath + "/intermediates/stripped_native_libs/${variant.toLowerCase()}/out/lib") {
into 'files/lib'
from(project("riru").buildDir.absolutePath + "/intermediates/stripped_native_libs/${variant.toLowerCase()}/out/lib") {
into 'zip/files/lib'
}
from(project(":rirud").buildDir.absolutePath + "/outputs/apk/${variant.toLowerCase()}/rirud.apk") {
from(project("rirud").buildDir.absolutePath + "/outputs/apk/${variant.toLowerCase()}/rirud.apk") {
include 'rirud.apk'
into 'files/'
into 'zip/files/'
}
}
}
}

task("zip${variant}", type: Zip) {
task("zip${variant}") {
dependsOn("prepareUpdateFiles${variant}")
doLast {
from flashDir
archiveName zipName
destinationDir outDir
}
}

task("push${variant}", type: Exec) {
dependsOn("zip${variant}")
doLast {
workingDir outDir
commandLine "adb", "push", zipName, "/data/local/tmp/"
exec {
workingDir flashDir
commandLine "./flashable.sh"
}
}
}

task("flash${variant}", type: Exec) {
dependsOn("zip${variant}")
dependsOn("prepareUpdateFiles${variant}")
doLast {
commandLine "adb", "sideload", "${outDir}/${zipName}"
exec {
workingDir flashDir
commandLine "./flashable.sh", "-s"
}
}
}
}
2 changes: 1 addition & 1 deletion rirud/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {

dependencies {
implementation 'dev.rikka.rikkax.io:little-endian-data-stream:1.0.2'
compileOnly project(':stub')
compileOnly getProject("stub")
}

android.applicationVariants.all { variant ->
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencyResolutionManagement {
}
}

include ':riru', ':stub', ':rirud'
include 'riru', 'stub', 'rirud'

import org.apache.tools.ant.DirectoryScanner

Expand Down
77 changes: 77 additions & 0 deletions template/update_package/flashable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

usage() {
echo "Usage: $0 [OPTION...]" 1>&2;
echo " " 1>&2;
echo "Valid options: " 1>&2;
echo " -h Print this help." 1>&2;
echo " -o ZIPFILE Name of the flashable zip file. Default value is update.zip." 1>&2;
echo " -d DIRECTORY Directory to include in the zip file. Default value is zip." 1>&2;
echo " -s Sideload the flashable zip to the connected Android device." 1>&2;
exit 1;
}

error(){
echo "Error: $*" >>/dev/stderr;
exit 1;
}

ZIPFILE="update.zip"
DIR="zip"
SIDELOAD=false

while getopts ":h:o:d:s" o; do
case "${o}" in
o)
ZIPFILE=${OPTARG}
;;
d)
DIR=${OPTARG}
;;
s)
SIDELOAD=true
;;
*)
usage
;;
esac
done

[ ! -d $DIR ] && error "$DIR directory does not exist."


echo "Building $ZIPFILE..."

current_dir=$(pwd)
cd $DIR

if [ "${ZIPFILE:0:1}" = "/" ]; then
zip -r $ZIPFILE . 1>/dev/null 2>/dev/null
else
zip -r $current_dir/$ZIPFILE . 1>/dev/null 2>/dev/null
fi

[ $? -ne 0 ] && error "Could not build $ZIPFILE, exiting..."

cd $current_dir

echo "Done."



[ $SIDELOAD = false ] && exit 0


ADB_PATH=$(which adb)

[ ! -f $ADB_PATH ] && error "Could not find adb."

IS_SIDELOAD=$($ADB_PATH devices 2>/dev/null | awk 'NR>1 {print $2}')

[ "$IS_SIDELOAD" != "sideload" ] && error "Cannot find sideload device."

echo "Sideloading..."

$ADB_PATH sideload $ZIPFILE

exit 0
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e7f2924

Please sign in to comment.