How to install Cordova Android Development Environment

How to install Cordova Android development environment

Android, Cordova, DevOps
How to install Cordova Android Development Environment

Bash script to install Cordova Android development environment with all dependencies on Ubuntu 24.04.

We're using it to build android applications on a cheap VPS. According to the algorithm:

  • raised the server
  • install dependencies
  • built the application
  • paid off the VPS

Login as root user sudo su and download bash script:

apt install wget
wget https://gist.githubusercontent.com/zionskynet/0687eb18c50bf12fd02b77c474cfd2b6/raw/1853afae62e363153d8def477bccd630a88e869e/cordova-android-dependencies.sh

Set permissions to execute a bash script:

chmod +x cordova-android-dependencies.sh

Run script:

./cordova-android-dependencies.sh

This will install:

  • JAVA 17 (openjdk-17-jdk + openjdk-17-jre)
  • Gradle 8.10.2
  • sdkmanager "platforms;android-34"
  • sdkmanager "build-tools;34.0.0"
  • NodeJS 18.xx
  • Apache Cordova framework

Bash script contents

#!/bin/bash
# run as root user
# chmod +x cordova-android-dependencies.sh
# ./cordova-android-dependencies.sh
# this script will install
# - java 17 (openjdk-17-jdk + openjdk-17-jre)
# - gradle 8.10.2
# - sdkmanager "platforms;android-34"
# - sdkmanager "build-tools;34.0.0"
# - nodejs 18.x
# - cordova
apt update
wait
apt install wget
wait
apt install zip unzip
wait
# java
# apt install openjdk-8-jdk openjdk-8-jre -y
apt install openjdk-17-jdk openjdk-17-jre -y
wait
# gradle
mkdir /opt/gradle
wait
cd /opt/gradle
wait
wget -nc "https://services.gradle.org/distributions/gradle-8.10.2-all.zip"
wait
unzip gradle-*.zip
wait
export GRADLE_HOME="/opt/gradle/gradle-8.10.2"
export PATH="$PATH:/opt/gradle/gradle-8.10.2/bin"
# export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https://services.gradle.org/distributions/gradle-8.10.2-all.zip"
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="file:///opt/gradle/gradle-8.10.2-all.zip"
# android sdk
cd /opt/
wait
wget -nc "https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip"
wait
mkdir -p /opt/android-sdk/cmdline-tools
wait
unzip -d /opt/android-sdk/cmdline-tools /opt/commandlinetools-linux-*.zip
wait
mv /opt/android-sdk/cmdline-tools/cmdline-tools /opt/android-sdk/cmdline-tools/latest
wait
export ANDROID_HOME="/opt/android-sdk"
export ANDROID_SDK_ROOT="/opt/android-sdk"
# export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
export PATH="$ANDROID_HOME/cmdline-tools/latest:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
# download and install android dependencies
wait
mkdir -p /root/.android
wait
touch "/root/.android/repositories.cfg"
wait
sdkmanager --update
wait
yes | sdkmanager --licenses
wait
sdkmanager platform-tools
# wait
# sdkmanager "platforms;android-33"
wait
sdkmanager "platforms;android-34"
# wait
# sdkmanager "build-tools;33.0.2"
wait
sdkmanager "build-tools;34.0.0"
wait
export PATH="$PATH:/opt/android-sdk/cmdline-tools/latest/bin/"
export PATH="$PATH:/opt/android-sdk/build-tools/34.0.0"
wait
# create bash script for autoload variables
cat > /etc/profile.d/android.sh << EOF
export GRADLE_HOME=/opt/gradle/gradle-8.10.2
export PATH="\$PATH:/opt/gradle/gradle-8.10.2/bin"
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="file:///opt/gradle/gradle-8.10.2-all.zip"
export ANDROID_HOME="/opt/android-sdk"
export ANDROID_SDK_ROOT="/opt/android-sdk"
export PATH="\$ANDROID_HOME/cmdline-tools/latest:\$ANDROID_HOME/cmdline-tools/latest/bin:\$ANDROID_HOME/platform-tools:\$PATH"
export PATH="\$PATH:/opt/android-sdk/cmdline-tools/latest/bin/"
export PATH="\$PATH:/opt/android-sdk/build-tools/34.0.0"
EOF
# export PATH="\$ANDROID_HOME/tools:\$ANDROID_HOME/tools/bin:\$ANDROID_HOME/platform-tools:\$PATH"
wait
chmod +x /etc/profile.d/android.sh
wait
# nodejs
apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates
wait
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
wait
apt-get install -y nodejs
wait
# cordova
npm install -g cordova
wait
# # Check installed dependencies:
# java -version
# gradle -v
# sdkmanager --help
# jarsigner --help
# keytool --help
# node -v
# cordova -v
# zipalign -v
# reboot

Check installed dependencies:

java -version
gradle -v
sdkmanager --help
jarsigner --help
keytool --help
zipalign -v
node -v
cordova -v

The installation script may not work, since everything is constantly changing, updated, and so on. If you experience errors related to Android SDK packages(sdkmanager, jarsigner, keytool, zipalign), let me know in comments:)

Alternatively you can install Android SDK via Bubblewrap CLI.