Got it! You want to automatically install Android Studio CLI tools (or at least set up an environment so the build scripts don’t fail trying to open Android Studio)** from Termux or your CLI environment** so the Capacitor command npx cap open android works smoothly without that error.
Key points:
Android Studio itself is a large GUI app, and cannot be fully installed from Termux or a CLI-only environment like a typical Linux CLI — it requires a GUI and lots of manual setup.
However, you can install just the Android SDK command line tools and related build tools which are enough for building and compiling your APK.
Then you configure Capacitor or your environment to use these CLI tools instead of Android Studio GUI.
How to fix / automate this setup:
- Install Android SDK Command Line Tools manually
You can download the Android SDK command line tools from Google:
https://developer.android.com/studio#command-line-tools
Download the latest command-line tools ZIP for Linux.
Then from Termux:
Create a folder for sdk¶
mkdir -p ~/Android/Sdk/cmdline-tools cd ~/Android/Sdk/cmdline-tools
Download the latest command line tools zip (use wget or curl)¶
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip
Unzip¶
unzip commandlinetools-linux-8512546_latest.zip
Move extracted content into a folder named "tools"¶
mv cmdline-tools tools
- Set environment variables
Add these lines to your ~/.bashrc or ~/.zshrc:
export ANDROID_SDK_ROOT=\(HOME/Android/Sdk export PATH=\)ANDROID_SDK_ROOT/cmdline-tools/tools/bin:\(ANDROID_SDK_ROOT/platform-tools:\)PATH
Reload your shell:
source ~/.zshrc # or ~/.bashrc
- Install SDK packages
Use sdkmanager to install required packages:
sdkmanager --sdk_root=$ANDROID_SDK_ROOT "platform-tools" "platforms;android-33" "build-tools;33.0.0"
Adjust Android versions to match your target.
- Configure Capacitor
Capacitor by default tries to open Android Studio GUI. To avoid the error:
When running npx cap open android, it tries to launch Android Studio GUI, which you don't have.
Instead, just build from CLI:
npx cap copy android cd android ./gradlew assembleDebug
This builds your APK without opening Android Studio GUI.
- Optional: Set CAPACITOR_ANDROID_STUDIO_PATH to a dummy
If you want to suppress the error, set the environment variable to a harmless path:
export CAPACITOR_ANDROID_STUDIO_PATH=/bin/true
This tricks the Capacitor open command into thinking Android Studio exists.
Summary
You cannot fully install Android Studio GUI from CLI/Termux automatically.
But you can install the Android SDK command line tools to build APKs.
Use ./gradlew assembleDebug for CLI builds.
Set CAPACITOR_ANDROID_STUDIO_PATH to avoid errors when running npx cap open android.
If you want, I can help you create a Termux bash script to download and install the SDK CLI tools and set up environment variables automatically. Want that?