From b4a50767c6cb70f8b405455df11235649b63048c Mon Sep 17 00:00:00 2001 From: Emily Toop Date: Mon, 23 Jul 2018 10:54:59 +0100 Subject: [PATCH] Add android build step --- .travis.yml | 29 ++++++++++++++++++++ cargo-config.toml.template | 11 ++++++++ scripts/create_standalone_ndk.sh | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100755 cargo-config.toml.template create mode 100755 scripts/create_standalone_ndk.sh diff --git a/.travis.yml b/.travis.yml index 86fcd597..6f28e0fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,3 +51,32 @@ matrix: script: - ./scripts/cargo_test.sh cache: cargo + - language: rust + dist: trusty + rust: stable + jdk: + - oraclejdk8 + env: + # Get revision number from https://dl.google.com/android/repository/repository2-1.xml + # Look for the string 'sdk-tools-linux-'. + - ANDROID_SDK_VERSION=4333796 + + before_install: + - > + PKG_OS="$TRAVIS_OS_NAME"; + export ANDROID_HOME="${HOME}/android-sdk"; + export PATH=$PATH:"${ANDROID_HOME}/tools/bin"; + mkdir $ANDROID_HOME + install: + # SDK Tools. + - > + curl -o sdk.zip "https://dl.google.com/android/repository/sdk-tools-${PKG_OS}-${ANDROID_SDK_VERSION}.zip" && + unzip -q sdk.zip -d $ANDROID_HOME; > /dev/null + # Android SDK and NDK + # Unfortunately we need to get rid of all output, otherwise it can easily fill up the 4 MB log limit + - yes | sdkmanager --licenses > /dev/null + - sdkmanager 'platform-tools' 'build-tools;27.0.0' 'platforms;android-27' 'ndk-bundle' > /dev/null + script: + - cd sdks/android/Mentat + - ./gradlew --no-daemon clean :library:assemble :library:test :library:lint + - cd ../../.. diff --git a/cargo-config.toml.template b/cargo-config.toml.template new file mode 100755 index 00000000..7fedb3d9 --- /dev/null +++ b/cargo-config.toml.template @@ -0,0 +1,11 @@ +[target.aarch64-linux-android] +ar = "$PWD/NDK/arm64/bin/aarch64-linux-android-ar" +linker = "$PWD/NDK/arm64/bin/aarch64-linux-android-clang" + +[target.armv7-linux-androideabi] +ar = "$PWD/NDK/arm/bin/arm-linux-androideabi-ar" +linker = "$PWD/NDK/arm/bin/arm-linux-androideabi-clang" + +[target.i686-linux-android] +ar = "$PWD/NDK/x86/bin/i686-linux-android-ar" +linker = "$PWD/NDK/x86/bin/i686-linux-android-clang" diff --git a/scripts/create_standalone_ndk.sh b/scripts/create_standalone_ndk.sh new file mode 100755 index 00000000..7348618b --- /dev/null +++ b/scripts/create_standalone_ndk.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +set -eu + +if [ -d NDK ]; then + printf '\033[33;1mStandalone NDK already exists... Delete the NDK folder to make a new one.\033[0m\n\n' + printf ' $ rm -rf NDK\n' + exit 0 +fi + +if [ ! -d "${ANDROID_SDK_ROOT-}" ]; then + ANDROID_SDK_ROOT=/usr/local/share/android-sdk +fi +if [ ! -d "${ANDROID_HOME-}" ]; then + ANDROID_HOME="$ANDROID_SDK_ROOT" +fi +if [ ! -d "${ANDROID_NDK_HOME-}" ]; then + ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle" +fi +MAKER="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py" + +if [ -x "$MAKER" ]; then + echo 'Creating standalone NDK...' +else + printf '\033[91;1mPlease install Android NDK!\033[0m\n\n' + printf ' $ sdkmanager ndk-bundle\n\n' + printf "\033[33;1mnote\033[0m: file \033[34;4m$MAKER\033[0m not found.\n" + printf 'If you have installed the NDK in non-standard location, please define the \033[1m$ANDROID_NDK_HOME\033[0m variable.\n' + exit 1 +fi + +mkdir NDK + +create_ndk() { + echo "($1)..." + "$MAKER" --api "$2" --arch "$1" --install-dir "NDK/$1" +} + +create_ndk arm64 24 +create_ndk arm 24 +create_ndk x86 24 + +echo 'Updating cargo-config.toml...' + +sed 's|$PWD|'"${PWD}"'|g' cargo-config.toml.template > cargo-config.toml