Skip to content

Instantly share code, notes, and snippets.

@erkineren
Last active January 25, 2022 08:44
Show Gist options
  • Save erkineren/0c009c335e8b33761dcc39074efe212a to your computer and use it in GitHub Desktop.
Save erkineren/0c009c335e8b33761dcc39074efe212a to your computer and use it in GitHub Desktop.
flutter adbf > build + install + stop + start + logcat

flutter adbf > build + install + stop + start + logcat

INFO

adbf.sh is adb-flutter command line script that composed with flutter and adb commands. Go to code

USAGE

  • Default behaviour (flutter build + stop app + install app + start app + show logcat of app) adbf.sh

  • You can combine all commands with passing arguments to script: Example: adbf.sh stop start logcat: Restart app and enter the logcat

  • Package name is automatically resolved from "android/app/build.gradle" file. If you want to use diffrent pacakge name you can set as env variable like

PACKAGE=com.example.app adbf start
  • You should run this script in root folder of flutter project

Available commands

  • build : this command will run fvm flutter build apk --release
adbf.sh build
  • start : this command will run adb shell am start -n $PACKAGE/.MainActivity
adbf.sh start
  • stop : this command will run adb shell am force-stop $PACKAGE
adbf.sh stop
  • install : this command will run adb install -r build/app/outputs/flutter-apk/app-release.apk
adbf.sh install
  • uninstall : this command will run adb uninstall $PACKAGE
adbf.sh uninstall
  • logcat : this command will run adb logcat --format color --dividers | grep `adb shell ps | grep $PACKAGE | awk '{print $2}'`
adbf.sh logcat
  • default
adbf.sh
#!/bin/sh
build(){
fvm flutter build apk --release
}
start(){
adb shell am start -n $PACKAGE/.MainActivity
}
stop(){
adb shell am force-stop $PACKAGE
}
install(){
adb install -r build/app/outputs/flutter-apk/app-release.apk
}
uninstall(){
adb uninstall $PACKAGE
}
logcat(){
adb logcat --format color --dividers | grep `adb shell ps | grep $PACKAGE | awk '{print $2}'`
}
default(){
build && (
stop
install && start && logcat
)
}
if [ -z "$PACKAGE" ]; then
PACKAGE=$(grep 'applicationId' $(pwd)/android/app/build.gradle | awk '{print $2}' | tr -d '"')
fi
if [ -z "$1" ]; then
default
else
for cmd in "$@"
do
$cmd
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment