Android – cat $fullPathToFile | pm install –user 0 -S $apkSize -> Sript

huangapple 未分类评论44阅读模式
英文:

Android - cat $fullPathToFile | pm install --user 0 -S $apkSize -> Sript

问题

因为在新的Android版本中,通过终端安装的命令

pm install --user 0 org.apkfile.apk

会失败,所以我使用以下的变通方法

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

(详见 https://stackoverflow.com/questions/50540334/install-apk-using-root-handling-new-limitations-of-data-local-tmp-folder)。

这个方法是有效的,但我希望有一个脚本能够从一个目录安装所有的apk文件。
测试输出的语句 echo "$file $apksize" 和 echo $fullpath/$file 都是正确的,while 循环也正常工作。

但我遇到了以下错误,没有安装任何应用:

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

[在Android终端上的错误截图][1]
[1]: https://i.stack.imgur.com/ZvODs.jpg

脚本内容:

#!/bin/sh
# 检查路径
fullpath="$PWD"
# 检查有多少个apk文件
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)
    # 在Debian上可以使用"du -b",但在Android终端上不支持选项b - $(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
英文:

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 https://stackoverflow.com/questions/50540334/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][1]
[1]: https://i.stack.imgur.com/ZvODs.jpg

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

huangapple
  • 本文由 发表于 2020年4月4日 22:57:29
  • 转载请务必保留本文链接:https://java.coder-hub.com/61029967.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定