android cli setup

2022-12-02 ยท 4 min read

install java (via sdkman) #

  • when you run sdk list java, there's a bunch of different options; I just installed whatever https://whichjdk.com/ recommended (11.0.17-tem) and it seems to work.
# ensure `.bashrc` contains these lines:
#
# ```
# export SDKMAN_DIR="$HOME/.local/sdkman"
#
# [[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] \
# 	&& source "$SDKMAN_DIR/bin/sdkman-init.sh"
# ```

# download the sdkman install script
$ cd ~/.local/
$ curl --proto '=https' --tlsv1.3 -sSf "https://get.sdkman.io?rcupdate=false" > sdkman-install.sh
$ sha256sum sdkman-install.sh
419762944a301418a6c68021c5c864f54a3ce3e013571bd38da448439695f582

# install sdkman
$ chmod a+x ./sdkman-install.sh
$ ./sdkman-install.sh
$ rm sdkman-install.sh

# reload $PATH
$ source ~/.bashrc

# install JDK
$ sdk list java
$ sdk install java 11.0.17-tem

# sanity check
$ which javac
/home/phlip9/.local/sdkman/candidates/java/current/bin/javac
$ javac --version
javac 11.0.17

install android cmdline-tools #

$ cd ~/.local/

# (linux) download
$ wget https://dl.google.com/android/repository/commandlinetools-linux-9123335_latest.zip -O commandlinetools.zip
$ sha256sum commandlinetools.zip
0bebf59339eaa534f4217f8aa0972d14dc49e7207be225511073c661ae01da0a

# (macOS) download
$ wget https://dl.google.com/android/repository/commandlinetools-mac-9123335_latest.zip -O commandlinetools.zip
$ sha256sum commandlinetools.zip
d0192807f7e1cd4a001d13bb1e5904fc287b691211648877258aa44d1fa88275

# see zip file structure
$ unzip -l commandlinetools.zip
cmdline-tools/bin/...
cmdline-tools/lib/...
cmdline-tools/...

# install into ~/.local/android/cmdline-tools/latest
$ mkdir -p android/cmdline-tools/latest
$ unzip commandlinetools.zip -d android/cmdline-tools/latest
$ mv android/cmdline-tools/latest/cmdline-tools/* android/cmdline-tools/latest/
$ rmdir android/cmdline-tools/latest/cmdline-tools
$ rm commandlinetools.zip

# ensure .bashrc contains these lines:
#
# ```
# # Android
# export ANDROID_HOME=$HOME/.local/android
# ANDROID_SDK_VERSION=33.0.1
# ANDROID_PATH=$ANDROID_HOME/cmdline-tools/latest/bin
# ANDROID_PATH=$ANDROID_PATH:$ANDROID_HOME/build-tools/$ANDROID_SDK_VERSION
# ANDROID_PATH=$ANDROID_PATH:$ANDROID_HOME/platform-tools
#
# export PATH=$PATH:$ANDROID_PATH
# ```

# sanity check
$ which sdkmanager
/home/phlip9/.local/android/cmdline-tools/latest/bin/sdkmanager
$ sdkmanager --version
8.0

install android SDK via sdkmanager #

# let's blindly accept all licenses : )
$ yes | sdkmanager --licenses

# check out the available SDK packages
$ sdkmanager --list
add-ons;addon-google_apis-google-24
build-tools;33.0.1
cmake;3.22.1
cmdline-tools;latest
emulator
extras;android;m2repository
extras;google;auto
extras;google;google_play_services
extras;google;instantapps
extras;google;m2repository
extras;google;market_apk_expansion
extras;google;market_licensing
extras;google;simulators
extras;google;webdriver
extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.0
extras;m2repository;com;android;support;constraint;constraint-layout-extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2
extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2
ndk-bundle
ndk;25.1.8937393
patcher;v4
platform-tools
platforms;android-33
platforms;android-TiramisuPrivacySandbox
skiaparser;3
sources;android-33
system-images;android-33;google_apis;arm64-v8a
system-images;android-33;google_apis;x86_64
system-images;android-33;google_apis_playstore;arm64-v8a
system-images;android-33;google_apis_playstore;x86_64
system-images;android-TiramisuPrivacySandbox;google_apis_playstore;arm64-v8a
system-images;android-TiramisuPrivacySandbox;google_apis_playstore;x86_64

# .. this goes on for a while

# install these. probably use the most recent versions?
$ sdkmanager --install \
	"build-tools;33.0.1" \
	"platform-tools" \
	"platforms;android-33" \
	"sources;android-33" \
	"ndk;25.1.8937393"

# sanity check
$ adb version
Android Debug Bridge version 1.0.41
Version 33.0.3-8952118
Installed as /home/phlip9/.local/android/platform-tools/adb

(optional) setup wireless debugging on device #

Connecting to your device via USB sucks. Here's how to develop for any local wifi-connected Android device.

  1. Device > Settings > Developer options > Wireless debugging > enable
  2. Device > Settings > Developer options > Wireless debugging (tap on the text, not the toggle button) > Pair device with pairing code
    • The device will then generate a pairing code and bind to a temporary port just for pairing. You should see a modal window pop up with the pairing info:
Wi-Fi pairing code
772405

IP address & Port
10.69.69.129:37269
  1. Host > run adb pair to pair with the device:
$ adb pair 10.69.69.129:37269 772405

You should see the host user@hostname under the "Paired Devices" section.

  1. Host > connect to the device:

To connect use the fixed device adb port:

$ adb connect phlipphone.lan:42835
connected to phlipphone.lan:42835
  1. Verify the device is actually attached:
$ adb devices
List of devices attached
phlipphone.lan:42835    device