1

Because the installation via terminal in new Android versions with

pm install --user 0 org.apkfile.apk

fails, I use the the workaround over

cat $fullPathToFile | pm install --user 0 -S $apkSize

(show Install APK using root, handling new limitations of "/data/local/tmp/" folder).

It works, but i would like a script to install all apks from one directory. It looks good,the test outputs echo "$file $apksize" and echo $fullpath/$file are right and the wihle loop works also.

But I get the following failure and nothing are installed:

"exception occurred while excecuting java.lang.NumberFormatException: null"
......................
...
....
...............
echo $testoutput1 #     echo "$file $apksize"
echo $testoutput2 #     echo $fullpath/$file

Failure on Android terminal The script:

#!/bin/sh
# check path
fullpath="$PWD"
# check how many apk files are there
files=$(ls -1 *apk | wc -l)

echo $fullpath

i=1;
while [ $i -le $files ]
do
    i=$(expr $i + 1)
    file=$(ls -1 *.apk | tail -n $i | head -n 1)
    # yes on debian you can use "du -b", but option b is not supported on android terminal - $(du -b $file | cut -f 1)
    apksize=$(wc -c $file | awk '{print $1}')
    cat "$fullpath/$file" | pm install --user 0 -S $apkSize
    echo "$file $apksize"
    echo $fullpath/$file
done
  • just some side notes *#!/bin/sh* doesn't exist should be *#!/system/bin/sh* you tagged this *bash* and *sh* but android runs *mksh* with *toybox* that mean *awk* doesn't exist (unless you have installed *busybox*) but `stat -c%s "$file"` will work (beware file names can have whitespaces) – alecxs Jun 14 '20 at 22:23

0 Answers0