Last active
July 7, 2024 23:23
-
-
Save RhinoLance/8f5c5277cea940f70eb6e32d618ffd33 to your computer and use it in GitHub Desktop.
Setup for building Cordova Android projects in a CI environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################### | |
# Start a docker container with 'docker run -it alpine:latest sh' and run the commands herein. | |
################################### | |
set -e | |
export BITBUCKET_BUILD_NUMBER=1 | |
export INSTALL_JDK_VERSION=17 | |
export INSTALL_ANDROID_SDK_VERSION=34.0.0 | |
export INSTALL_ANDROID_TOOLS_VERSION=11076708 # from https://developer.android.com/studio#command-line-tools-only | |
export INSTALL_NODE_VERSION=20 | |
export INSTALL_ANDROID_SDK_VERSION_MAJOR=$(echo $INSTALL_ANDROID_SDK_VERSION | sed 's/\..*//') | |
echo "Install JDK version: $INSTALL_JDK_VERSION" | |
echo "Install Android SDK version: $INSTALL_ANDROID_SDK_VERSION" | |
echo "Install Node.js version: $INSTALL_NODE_VERSION" | |
export WORKSPACE=/workspace | |
mkdir -p $WORKSPACE | |
apk update | |
################################### | |
# install JDK | |
################################### | |
echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories | |
apk add openjdk${INSTALL_JDK_VERSION}-jdk | |
java -version | |
export JAVA_HOME=/usr/lib/jvm/java-${INSTALL_JDK_VERSION}-openjdk | |
################################### | |
# install Android SDK | |
################################### | |
export ANDROID_HOME="${WORKSPACE}/android-sdk" >> /etc/profile | |
export ANDROID_SDK_ROOT="${ANDROID_HOME}" | |
export ANDROID_TOOLS="${ANDROID_HOME}/cmdline-tools/bin" | |
export CORDOVA_PATH="${WORKSPACE}/node_modules/cordova/bin" | |
export PATH="${PATH}:${ANDROID_TOOLS}:${CORDOVA_PATH}" | |
apk add wget curl maven gradle | |
# install Android SDK tools if necessary | |
if [ ! -d "${ANDROID_HOME}" ] | |
then | |
mkdir "${ANDROID_HOME}" | |
cd "${ANDROID_HOME}" | |
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip | |
unzip commandlinetools-linux-11076708_latest.zip | |
cd "${WORKSPACE}" | |
fi | |
# accept all SDK licenses, otherwise later processes will hang waiting for input | |
yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses | |
# install the supporting packages | |
yes | sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools" "build-tools;${INSTALL_ANDROID_SDK_VERSION}" # required so cordova can build app | |
yes | sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${INSTALL_ANDROID_SDK_VERSION_MAJOR}" | |
################################### | |
# install Node.js | |
################################### | |
apk add nodejs npm | |
node -v && npm -v | |
################################### | |
# Install other tools | |
################################### | |
apk add git openssh-client | |
################################### | |
# init project | |
################################### | |
npm i -g cordova | |
cordova create myApp com.myCompany.myApp myApp | |
cd myApp | |
cordova platform add android | |
cordova requirements android | |
cordova build android --verbose | |
echo "all done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment