Skip to content

Commit

Permalink
RSDK-6740 local tarball support (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Jun 3, 2024
1 parent 8563f40 commit fcd3fa4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,47 +76,37 @@ class AndroidModulePlugin implements Plugin<Project> {
}

new File(tmpModDir, "mod.sh").text = modScript
project.exec {
commandLine "chmod", "+x", "${tmpModDir}/mod.sh"
}

project.copy {
from project.file("${tmpModDir}/mod.sh")
into outputDir
filter { line ->
line.
replaceAll('__MODULE_JAR_PATH__', './module.jar').
replaceAll('__MAIN_ENTRY_CLASS__', extension.mainEntryClass.get()).
replaceAll('__FORCE_32__', extension.force32Bit.getOrElse(false).toString())
}
}
}
}

project.task("copyModule${variant.name.capitalize()}", type: CopyModuleTask) {
dependsOn assembleTask

from.set(outputDir)
def copyMetaTask = project.task("copyMeta${variant.name.capitalize()}") {
doLast {
new File(outputDir, "meta.json").text = getClass().getResourceAsStream("/meta.json").getText()
}
}

project.task("pushModuleAdb${variant.name.capitalize()}", type: Exec) {
def tarModuleTask = project.task("tarModule${variant.name.capitalize()}", type: Exec) {
dependsOn assembleTask
commandLine "tar", "czf", "${outputDir}/module.tar.gz", "-C", outputDir, "mod.sh", "module.jar"
}

def outputDirPush = "${project.layout.buildDirectory.get()}/outputs/module_adb/${variant.name}"
doFirst {
project.copy {
from project.file("${tmpModDir}/mod.sh")
into outputDirPush
filter { line ->
line.
replaceAll('__MODULE_JAR_PATH__', '/sdcard/Download/module.jar').
replaceAll('__MAIN_ENTRY_CLASS__', extension.mainEntryClass.get()).
replaceAll('__FORCE_32__', extension.force32Bit.getOrElse(false).toString())
}
}
project.copy {
from project.file("${outputDir}/module.jar")
into outputDirPush
}
}
commandLine "adb", "push", "${outputDirPush}/module.jar", "${outputDirPush}/mod.sh", "/sdcard/Download"
project.task("pushModuleAdb${variant.name.capitalize()}", type: Exec) {
dependsOn(copyMetaTask, tarModuleTask)
def destDir = "/sdcard/Download/${project.rootProject.projectDir.name}"
commandLine "bash", "-c", "adb shell mkdir -p ${destDir} && adb push ${outputDir}/module.tar.gz ${outputDir}/meta.json ${destDir}"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions android/module-plugin/src/main/resources/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entrypoint": "mod.sh"
}
16 changes: 3 additions & 13 deletions android/module-plugin/src/main/resources/mod-in-process.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#!/bin/sh

CWD=`pwd`
JAR_PATH=__MODULE_JAR_PATH__
JAR_PARENT_PATH="$(realpath $(dirname "$JAR_PATH"))"

# only copy the jar if it is not next to our script
if [ "$JAR_PARENT_PATH" == "$CWD" ]; then
SAFE_JAR_PATH=$JAR_PATH
else
SAFE_JAR_PATH=$(mktemp -d -p `pwd`)
cp $JAR_PATH $SAFE_JAR_PATH/module.jar
SAFE_JAR_PATH=$SAFE_JAR_PATH/module.jar
fi
JAR_PATH=./module.jar

ABI_LIST=`getprop ro.product.cpu.abilist`
ABI_ARRAY=(${ABI_LIST//,/ })

LIBRARY_PATH=
for abi in "${ABI_ARRAY[@]}"
do
NEXT_PATH_TMP=$SAFE_JAR_PATH!/lib/$abi
NEXT_PATH_TMP=$JAR_PATH!/lib/$abi
if [ -z "$LIBRARY_PATH" ]; then
LIBRARY_PATH=$NEXT_PATH_TMP
else
Expand All @@ -44,7 +34,7 @@ trap removeTempFile EXIT
intentURI="intent:#Intent;action=com.viam.rdk.fgservice.START_MODULE"
intentURI="$intentURI;S.secret=$_VIAM_FG_SECRET"
intentURI="$intentURI;S.proc_file=$proc_file"
intentURI="$intentURI;S.java_class_path=$SAFE_JAR_PATH"
intentURI="$intentURI;S.java_class_path=$JAR_PATH"
intentURI="$intentURI;S.java_library_path=$LIBRARY_PATH"
intentURI="$intentURI;S.java_entry_point_class=__MAIN_ENTRY_CLASS__"
saveIFS="$IFS"
Expand Down
16 changes: 3 additions & 13 deletions android/module-plugin/src/main/resources/mod.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#!/bin/sh

CWD=`pwd`
JAR_PATH=__MODULE_JAR_PATH__
JAR_PARENT_PATH="$(realpath $(dirname "$JAR_PATH"))"

# only copy the jar if it is not next to our script
if [ "$JAR_PARENT_PATH" == "$CWD" ]; then
SAFE_JAR_PATH=$JAR_PATH
else
SAFE_JAR_PATH=$(mktemp -d -p `pwd`)
cp $JAR_PATH $SAFE_JAR_PATH/module.jar
SAFE_JAR_PATH=$SAFE_JAR_PATH/module.jar
fi
JAR_PATH=./module.jar

ABI_LIST=`getprop ro.product.cpu.abilist`
ABI_ARRAY=(${ABI_LIST//,/ })

LIBRARY_PATH=
for abi in "${ABI_ARRAY[@]}"
do
NEXT_PATH_TMP=$SAFE_JAR_PATH!/lib/$abi
NEXT_PATH_TMP=$JAR_PATH!/lib/$abi
if [ -z "$LIBRARY_PATH" ]; then
LIBRARY_PATH=$NEXT_PATH_TMP
else
Expand All @@ -43,6 +33,6 @@ fi

# app_process is the closest thing to being able to run a Zygote without actually running an
# [Native]Activity. It will give us all the android runtime dependencies we need.
${APP_PROCESS_NAME} -Djava.class.path="$SAFE_JAR_PATH" -Djava.library.path="$LIBRARY_PATH" \
${APP_PROCESS_NAME} -Djava.class.path="$JAR_PATH" -Djava.library.path="$LIBRARY_PATH" \
/system/bin __MAIN_ENTRY_CLASS__ "$@"
exit $?

0 comments on commit fcd3fa4

Please sign in to comment.