Skip to content

Instantly share code, notes, and snippets.

@Envek
Created December 28, 2022 09:54
Show Gist options
  • Save Envek/d3ea9747058260f5b971d110b38e2329 to your computer and use it in GitHub Desktop.
Save Envek/d3ea9747058260f5b971d110b38e2329 to your computer and use it in GitHub Desktop.
If you have an application installed on one device, but for some reason can't install it on another via Play Market (e.g. dumb country restrictions!), then this script will allow you to grab APKs from one phone and install them on another!
#!/bin/sh
usage() {
echo "Android application copy from one device to another via ADB APK files copy (requires USB debugging to be enabled)"
echo "Usage: $0 <application_id> [application_id…]"
echo "Example: $0 jp.naver.line.android"
}
if [ $# -eq 0 ]; then usage; exit 1; fi
if [ "$1" = '--help' ]; then usage; exit 0; fi
if [ "$1" = '-h' ]; then usage; exit 0; fi
read -p "Connect source phone via USB and press ENTER"
tmp_dir=$(mktemp -d -t apk-copy-XXXXXXXXXX)
while [ "$1" != "" ]; do
app_id="$1"
mkdir -p "${tmp_dir}/${app_id}"
echo "Pulling APK files for $app_id to $tmp_dir/$app_id"
apks=$(adb shell pm path "$app_id" | awk '{print $NF}' FS=':')
IFS=$'\n'
for apk in $apks; do
filename=$(basename "$apk")
echo "Fetching $filename"
adb pull "$apk" "${tmp_dir}/${app_id}/${filename}"
done
shift
done
echo
read -p "Connect recipient phone via USB and press ENTER"
for $dir in "$tmp_dir"; do
echo "Installing APK files from $dir"
adb install-multiple -r "$dir"/*.apk
done
rm -rf "$tmp_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment