Skip to content
Snippets Groups Projects
Commit a06d5865 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Add scripts directory with android scripts

parent 5eb7ef3c
No related branches found
No related tags found
No related merge requests found
Pipeline #7516 failed
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-android.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
# Run the build
echo "Running cordova build..."
ionic cordova build android --warning-mode=none --color
#ionic cordova build android --warning-mode=none --color --verbose
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
cd ${PROJECT_DIR}
PWD=$(pwd)
CMD="sudo docker run -ti --rm -p 8100:8100 -p 35729:35729 -v $PWD:/cesium:rw cesium:release"
echo "Executing: $CMD"
$CMD
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
cd ..
PROJECT_DIR=`pwd`
export PROJECT_DIR
fi;
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-android.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
# Run the build
echo "Running Android emulator..."
ionic cordova emulate android --warning-mode=none --color
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Preparing environment
. ${PROJECT_DIR}/scripts/env-global.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
if [[ "_" == "_${CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL}" ]]; then
echo "Missing Gradle distribution URL - please export env variable 'CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'"
exit 1
fi
echo "Preparing Android environment:"
echo " - using Android SDK: ${ANDROID_SDK_ROOT}"
echo " - using Android SDK tools: ${ANDROID_SDK_TOOLS_ROOT}"
echo " - using Gradle: ${CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL}"
echo " - using Java: ${JAVA_HOME}"
echo " - project dir: ${PROJECT_DIR}"
cd ${PROJECT_DIR}
# Prepare Android platform
if [[ ! -d "${PROJECT_DIR}/platforms/android" ]]; then
echo "Adding Cordova Android platform..."
ionic cordova prepare android --color --verbose
if [[ $? -ne 0 ]]; then
exit 1
fi
fi
# Copy local files
if [[ -d "${PROJECT_DIR}/.local/android" ]]; then
echo "Copying files from directory '${PROJECT_DIR}/.local/android' into '${PROJECT_DIR}/platforms/android'..."
cp -rf ${PROJECT_DIR}/.local/android/* ${PROJECT_DIR}/platforms/android
if [[ $? -ne 0 ]]; then
exit 1
fi
else
echo "No directory '${PROJECT_DIR}/.local/android' found. Please create it, with a file 'release-signing.properties' for release signing"
fi
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
if [[ ! -f "${PROJECT_DIR}/package.json" ]]; then
echo "Invalid project dir: file 'package.json' not found in ${PROJECT_DIR}"
echo "-> Make sur to run the script 'prepare_env.sh' from the project directory, or export env variable 'PROJECT_DIR'"
exit 1
fi;
cd ${PROJECT_DIR}
#echo "Cleaning project dependencies..."
#rm -rf node_modules
echo "Cleaning Cordova plugins..."
rm -rf plugins
echo "Cleaning Android platform..."
#rm -rf platforms/android
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
if [[ ! -f "${PROJECT_DIR}/package.json" ]]; then
echo "Invalid project dir: file 'package.json' not found in ${PROJECT_DIR}"
echo "-> Make sure to run the script inside his directory, or export env variable 'PROJECT_DIR'"
exit 1
fi;
echo "Preparing project environment.."
NODEJS_VERSION=10
ANDROID_NDK_VERSION=r19c
ANDROID_SDK_VERSION=r29.0.0
ANDROID_SDK_TOOLS_VERSION=4333796
ANDROID_SDK_ROOT=/usr/lib/android-sdk
ANDROID_SDK_TOOLS_ROOT=${ANDROID_SDK_ROOT}/build-tools
#JAVA_HOME=
GRADLE_VERSION=4.10.3
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
# Override with a local file, if any
if [[ -f "${PROJECT_DIR}/.local/env.sh" ]]; then
echo "Loading environment variables from: '.local/env.sh'"
source ${PROJECT_DIR}/.local/env.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
else
echo "No file '${PROJECT_DIR}/.local/env.sh' found. Will use defaults"
fi
# Checking Java installed
if [[ "_" == "_${JAVA_HOME}" ]]; then
JAVA_CMD=`which java`
if [[ "_" == "_${JAVA_CMD}" ]]; then
echo "No Java installed. Please install java, or set env variable JAVA_HOME "
exit 1
fi
fi
# Checking Android SDK
if [[ "_" == "_${ANDROID_SDK_ROOT}" ]]; then
echo "Please set env variable ANDROID_SDK_ROOT "
exit 1
fi
if [[ ! -d "${ANDROID_SDK_ROOT}" ]]; then
echo "Invalid path for ANDROID_SDK_ROOT: ${ANDROID_SDK_ROOT} is not a directory"
exit 1
fi
# Export useful variables
export PROJECT_DIR \
JAVA_HOME \
ANDROID_SDK_ROOT \
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL
# Node JS
export NVM_DIR="$HOME/.nvm"
if [[ -d "${NVM_DIR}" ]]; then
# Load NVM
. ${NVM_DIR}/nvm.sh
# Switch to expected version
nvm use ${NODEJS_VERSION}
# Or install it
if [[ $? -ne 0 ]]; then
nvm install ${NODEJS_VERSION}
if [[ $? -ne 0 ]]; then
exit 1;
fi
fi
else
echo "nvm (Node version manager) not found (directory ${NVM_DIR} not found). Please install, and retry"
exit -1
fi
# Install global dependencies
IONIC_PATH=`which ionic`
CORDOVA_PATH=`which cordova`
if [[ "_" == "_${IONIC_PATH}" || "_" == "_${CORDOVA_PATH}" ]]; then
echo "Installing global dependencies..."
npm install -g cordova ionic native-run yarn
if [[ $? -ne 0 ]]; then
exit 1
fi
fi
NATIVE_RUN_PATH=`which native-run`
if [[ "_" == "_${NATIVE_RUN_PATH}" ]]; then
echo "Installing global dependencies..."
npm install -g native-run
if [[ $? -ne 0 ]]; then
exit 1
fi
fi
# Install project dependencies
if [[ ! -d "${PROJECT_DIR}/node_modules" ]]; then
echo "Installing project dependencies..."
cd ${PROJECT_DIR}
yarn
fi
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-global.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
echo "Updating Ionic..."
npm update -g ionic@latest
echo "Updating Cordova..."
npm update -g cordova@latest
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Updating Cordova plugins..."
ionic cordova platform update android --save
if [[ $? -ne 0 ]]; then
exit 1
fi
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-android.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
# Run the build
echo "Running cordova build..."
ionic cordova build android --warning-mode=none --color --prod --release
# TODO: try this :
#ionic cordova build android --warning-mode=none --color --prod --release --optimizejs --minifyjs --minifycss
if [[ $? -ne 0 ]]; then
exit 1
fi
# Signature
KEYSTORE_FILE=${PROJECT_DIR}/.local/Cesium.keystore
KEY_ALIAS=Cesium
KEY_PWD=
APK_DIR=${PROJECT_DIR}/platforms/android/build/outputs/apk/release
APK_UNSIGNED_FILE=${APK_DIR}/android-release.apk
BUILD_TOOLS_DIR="${ANDROID_SDK_ROOT}/build-tools/28.*/"
if [[ ! -f "${APK_UNSIGNED_FILE}" ]]; then
echo "APK file not found at: ${APK_UNSIGNED_FILE}"
exit 1
fi
# Check if signed
cd ${BUILD_TOOLS_DIR}
./apksigner verify ${APK_UNSIGNED_FILE}
# Not signed ? Do it !
if [[ $? -ne 0 ]]; then
echo "It seems that the APK file ${APK_UNSIGNED_FILE} is not signed !"
if [[ ! -f "${KEYSTORE_FILE}" ]]; then
echo "ERROR: Unable to sign: no keystore file found at ${KEYSTORE_FILE} !"
exit 1
fi
echo "Signing APK file ${APK_UNSIGNED_FILE}..."
APK_SIGNED_FILE=${APK_DIR}/android-release-signed.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ${KEYSTORE_FILE} ${APK_UNSIGNED_FILE} Cesium
BUILD_TOOLS_DIR="${ANDROID_SDK_ROOT}/build-tools/28.*/"
cd ${BUILD_TOOLS_DIR}
./zipalign -v 4 ${APK_UNSIGNED_FILE} ${APK_SIGNED_FILE}
./apksigner verify ${APK_SIGNED_FILE}
if [[ $? -ne 0 ]]; then
echo "Signing failed !"
exit 1
fi
# Do file replacement
rm ${APK_UNSIGNED_FILE}
mv ${APK_SIGNED_FILE} ${APK_UNSIGNED_FILE}
fi
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-android.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
# Run the build
echo "Building Android application..."
ionic cordova build android --warning-mode=none --color --device
echo "Running Android application..."
native-run android --app ${PROJECT_DIR}/platforms/android/build/outputs/apk/debug/android-debug.apk --device
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
# Default env (can be override in file <PROJECT>/.local/env.sh)
KEYSTORE_FILE=${PROJECT_DIR}/.local/android/Cesium.keystore
KEY_ALIAS=Cesium
KEYSTORE_PWD=
APK_RELEASE_DIR=${PROJECT_DIR}/platforms/android/build/outputs/apk/release
APK_UNSIGNED_FILE=${APK_RELEASE_DIR}/android-release-unsigned.apk
APK_SIGNED_FILE=${APK_RELEASE_DIR}/android-release-signed.apk
# Preparing Android environment
. ${PROJECT_DIR}/scripts/env-android.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ${PROJECT_DIR}
# Sign files
echo "Signing APK file..."
if [[ ! -f "${APK_UNSIGNED_FILE}" ]]; then
echo "APK file not found: ${APK_UNSIGNED_FILE}"
exit 1
fi
if [[ ! -f "${KEYSTORE_FILE}" ]]; then
echo "Keystore file not found: ${KEYSTORE_FILE}"
exit 1
fi
# Remove previous version
if [[ -f "${APK_SIGNED_FILE}" ]]; then
echo "Delete previous signed APK file: ${APK_SIGNED_FILE}"
rm -f ${APK_SIGNED_FILE}
fi
echo "Executing jarsigner..."
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ${KEYSTORE_FILE} ${APK_UNSIGNED_FILE} Cesium
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Executing jarsigner [OK]"
BUILD_TOOLS_DIR="${ANDROID_SDK_ROOT}/build-tools/28.*/"
cd ${BUILD_TOOLS_DIR}
echo "Executing zipalign..."
./zipalign -v 4 ${APK_UNSIGNED_FILE} ${APK_SIGNED_FILE}
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Executing zipalign [OK]"
echo "Verify APK signature..."
./apksigner verify ${APK_SIGNED_FILE}
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Verify APK signature [OK]"
echo "Successfully generated signed APK at: ${APK_SIGNED_FILE}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment