Notes on how to build and run an Android application from the command line

As a brief note to self, this is how I compiled/built an Android application (APK) from the MacOS command line and then ran it in an emulator. I include both my application- and system-specific notes, as well as the more generic commands I found at this Android.com URL:

- build a “debug apk”
    - COMMAND: `gradlew assembleDebug`
    - This creates an APK named module_name-debug.apk in 
      project_name/module_name/build/outputs/apk/
    - MINE: ./app/build/outputs/apk/app-debug.apk
- need to start an emulator
    - COMMAND: emulator -avd avd_name
    - MINE:    emulator -avd Pixel_2_API_27_Oreo_8.1_
        - HOW TO LIST EMULATORS: `emulator -list-avds`
            Nexus_5X_API_25_7.1.1_
            Nexus_9_API_23_6.0_
            Nexus_9_API_25
            Pixel_2_API_27_Oreo_8.1_
            Pixel_C_API_25_Android_7.1.1_
        - emulator dir: ~/Library/Android/sdk/emulator
- install onto the emulator:
    - COMMAND: adb install path/to/your_app.apk
    - MINE:    adb install ./app/build/outputs/apk/app-debug.apk

Notes:

  • In a dev environment you build a debug APK (that’s also signed)
  • On a Mac/macOS system, the Android SDK is in the directory shown (~/Library/Android/sdk), assuming that it was installed with Android Studio
  • The adb command won’t work if you have more than one emulator running

If you ever want/need to build an Android application from the command line, I hope these notes are helpful.