KC Blog

分享我在 2022 年開發Android App中最常用的指令

3 min read
AndroidDev#Android#CLI#adb#brew#develop

  Preview

  • when I am developing that I always used brew to install some cli tool.

    • install brew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  Android

  • How to install test aab file

    • install bundletool

      brew install bundletool

    • switch to your aab file folder and convert it to apk file

      bundletool build-apks --bundle=./app.aab --output=./app.apks

    • install apk

      bundletool install-apks --apks=app.apks

  • Adb tool that I often used

    • Clear app data

    adb shell pm clear your.package.name

    • Delete app

    adb uninstall your.package.name

    • Search app package

    adb shell pm list packages | grep 'keyword'

    • Disable app

    adb shell pm disable-user 'your.package.name'

    • Open app

    adb shell am start -n your.package.name

    • Open app and goto assign page

    adb shell am start -n your.package.name/your.assign.activity.path

    • Forec-stop apps

    adb shell am force-stop your.package.name

    • Open Accessibility page

    adb shell am start -a android.settings.ACCESSIBILITY_SETTINGS

    • Open Device admin page

    adb shell am start -n android.app.extra.DEVICE_ADMIN

    • Set device owner

    adb -d shell dpm set-device-owner your.package.name/.your.admin.receivers.path

    • Remove device owner

    adb shell dpm remove-active-admin your.package.name/.your.admin.receivers.path

    • Dumpsys device owner info

    adb shell dumpsys device_policy

    • Grant app permissions

    adb shell "pm grant your.package.name android.permission.YourPermission && am force-stop elegant.access.aidltest"

    • Pull files

    adb pull /your/path

  bootloader

  • The step of recovery Android phone use the office OTA
  1. Update bootloader
`fastboot flash bootloader bootloader-bullhead-xxxVersion.img`
  1. Reboot bootloader
`fastboot reboot-bootloader`
  1. Update radio
`fastboot flash radio radio-bullhead-xxxx-x.x.xx.x.xx.img`
  1. Reboot bootloader
`fastboot reboot-bootloader`
  1. Flash system
`fastboot flash system system.img`
  1. Flash vendor
`fastboot flash vendor vendor.img`
  1. Flash user data (This step will clear your internal storage.)
`fastboot flash userdata userdata.img`
  1. Flash boot
`fastboot flash boot boot.img`
  1. Flash recovery
`fastboot flash recovery recovery.img`
  1. Clear cache
`fastboot erase cache`
  1. Flash cache
`fastboot flash cache cache.img`
  1. Reboot android OS
`fastboot reboot`

  Git

  I like to use git command line to control my repo instead of git GUI tool.

  • Let your git graph not merge together and not commit after you sent the cli.

git merge --no-ff --no-commit hash

  • Edit your commit
`git commit --amend`
  • Rebase and sync your local repo with remote
`git pull origin --rebase`
  • Story/Recovery/Show your not finish work

git stash --include-untracked 、 git stash pop、 git list

  • See your local git info
`git config -l`
  • Base git concept
`git add , git commit , git push , git checkout, git pull , git cherry-pick, git branch , git remote...etc.`

  Others

  • See Java environment

/usr/libexec/java_home -V