Skip to content

Instantly share code, notes, and snippets.

@omar2205
Last active March 31, 2024 15:27
Show Gist options
  • Save omar2205/721cd06a57af1f91c64ecdb97de71ecc to your computer and use it in GitHub Desktop.
Save omar2205/721cd06a57af1f91c64ecdb97de71ecc to your computer and use it in GitHub Desktop.
Setup Android command line only - Ubuntu

Setup Android cmd-tools for Ubuntu

Install java

sudo apt install -y openjdk-8-jdk

You can switch between java version with sudo update-alternatives --config java

check with: java --version; javac --version

Download commandlinetools-linux

From here https://developer.android.com/studio/index.html#command-tools

I'm gonna use $HOME/dev/Android. Make an empty dir inside Android called cmdline-tools, unzip and rename the extracted cmdline-tools to tools and move it inside cmdline-tools.

  $HOME/dev/Android:
    - cmdline-tools:
      - tools (downloaded and renamed)

Edit .bashrc:

export ANDROID_SDK_ROOT=$HOME/dev/Android
export ANDROID_HOME=$HOME/dev/Android # support some legacy tools
PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

Install the SDK

sdkmanager 'platform-tools' 'platforms;android-30'

@omar2205
Copy link
Author

For building Capacitor project

  • npx cap sync

Building Android projects:

  • cd android

Dev:

  • ./gradlew assembleDebug

Production:

  • ./gradlew assembleRelease
  • cd app/build/outputs/apk/release
  • jarsigner -keystore KEYSTORE_PATH -storepass KEYSTORE_PASS app-release-unsigned.apk KEYSTORE_ALIAS
  • zipalign 4 app-release-unsigned.apk app-release.apk

developer.android.com: Sign your app from command line
assembleRelease vs installRelease vs bundleRelease

@omar2205
Copy link
Author

Setting up an emulator

Run sdkmanager --list to list all available images and pick one.

I'm picking system-images;android-32;google_apis_playstore;x86_64

To install it use sdkmanager --install <REPLACE_SYSTEM_NAME>

So run: sdkmanager --install system-images;android-32;google_apis_playstore;x86_64

Creating an avd

Run echo "no" | avdmanager --verbose create avd --force --name "test_1" --package "system-images;android-32;google_apis_playstore;x86_64"

Where test_1 is the name of the avd and --package "" is the name of the image we installed above

Launch the emulator

If you followed the setup process above, then cd to ~/dev/Android/tools

Run ./emulator @test_1
if you want software rendering run ./emulator -gpu guest @test_1

@omar2205
Copy link
Author

sudo apt install -y openjdk-17-jdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment