You can do adb shell pm list packages
, and after reading through the list, do an adb shell pm path "com.yourpackage"
to get the full path and do a simply adb pull
.
Fact is: I want to automate this. I thought about a really simple bash script:
for apk in $(adb shell pm list packages | sed 's/package://g' | sort); do
# If you just do an echo, IT WORKS
# echo $apk
# But here it doesn't work
adb shell pm path $apk
done
But that simply doesn't work. It seems that "$apk" becomes lost or something and nothing is shown in that snippet. I don't know if it's a subshell problem, or some peculiarity when using variables that got through an adb shell.
Should I create a script apks.sh just using pm list
, for and such, push it to my device, run adb shell
only once and execute apks.sh?
adb shell "pm path $apk"
and see if that works. Quoting it such makes clear the entire thing should be passed toadb shell
. Without the quotes, it's not clear whether the$apk
is 2nd param topm
or 5th param toadb
;)pm list packages
, just aspm path [PACKAGE]
, results in the output being preceded by the "package:" string. A way to circumvent this would be to iterate through thepm list packages
with something like the following:for i in $(pm list packages); do
. Then, inside the loop, you'll define a variablevar
with the content ofi
, such as in:var=$i
. Next, you'll trim the "package:" withvar="${var#p*:}"
, which will return the package name. After that, passvar
throughpm path
, as in:pm path $var
, and trim "package:" once more.apk
belongs to the Linux terminal only. At line 4, you're trying to passapk
to thepm
as if it were an Android shell variable.