diff --git a/android/module-plugin/src/main/groovy/com/viam/sdk/android/module/android-module-plugin.groovy b/android/module-plugin/src/main/groovy/com/viam/sdk/android/module/android-module-plugin.groovy index b5722c9fa..f467b9c8d 100644 --- a/android/module-plugin/src/main/groovy/com/viam/sdk/android/module/android-module-plugin.groovy +++ b/android/module-plugin/src/main/groovy/com/viam/sdk/android/module/android-module-plugin.groovy @@ -76,13 +76,15 @@ class AndroidModulePlugin implements Plugin { } 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()) } @@ -90,33 +92,21 @@ class AndroidModulePlugin implements Plugin { } } - 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}" } } } diff --git a/android/module-plugin/src/main/resources/meta.json b/android/module-plugin/src/main/resources/meta.json new file mode 100644 index 000000000..e1027ad43 --- /dev/null +++ b/android/module-plugin/src/main/resources/meta.json @@ -0,0 +1,3 @@ +{ + "entrypoint": "mod.sh" +} diff --git a/android/module-plugin/src/main/resources/mod-in-process.sh b/android/module-plugin/src/main/resources/mod-in-process.sh index cc71b4f33..e70f59406 100644 --- a/android/module-plugin/src/main/resources/mod-in-process.sh +++ b/android/module-plugin/src/main/resources/mod-in-process.sh @@ -1,17 +1,7 @@ #!/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//,/ }) @@ -19,7 +9,7 @@ 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 @@ -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" diff --git a/android/module-plugin/src/main/resources/mod.sh b/android/module-plugin/src/main/resources/mod.sh index 1333faeef..0b22616d3 100644 --- a/android/module-plugin/src/main/resources/mod.sh +++ b/android/module-plugin/src/main/resources/mod.sh @@ -1,17 +1,7 @@ #!/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//,/ }) @@ -19,7 +9,7 @@ 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 @@ -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 $?