Browse Source

Add NDK

master
Ambrose Chua 4 years ago
parent
commit
c4fa443552
  1. 65
      ndk/Dockerfile
  2. 66
      ndk/release

65
ndk/Dockerfile

@ -0,0 +1,65 @@
# Android Dockerfile based on uber/android-build-environment
FROM ubuntu:18.04
# SDK version
ENV ANDROID_SDK_VERSION 4333796
ENV PLATFORM_VERSION 28
ENV BUILD_TOOLS_VERSION 28.0.2
# Never ask for confirmations
ENV DEBIAN_FRONTEND noninteractive
# Update apt-get
RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends \
software-properties-common \
unzip \
wget \
zip \
xxd \
&& apt-add-repository ppa:openjdk-r/ppa \
&& apt-get -qq update \
&& apt-get -qq install -y openjdk-8-jdk \
-o Dpkg::Options::="--force-overwrite" \
&& apt-get -qq autoremove -y \
&& apt-get -qq clean \
&& rm -rf /var/lib/apt/lists/*
# Install Android SDK
RUN wget https://dl.google.com/android/repository/sdk-tools-linux-$ANDROID_SDK_VERSION.zip -q \
&& mkdir /usr/local/android \
&& unzip -q sdk-tools-linux-$ANDROID_SDK_VERSION.zip -d /usr/local/android \
&& rm sdk-tools-linux-$ANDROID_SDK_VERSION.zip
# Export JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
# Environment variables
ENV ANDROID_HOME /usr/local/android
ENV ANDROID_SDK_HOME $ANDROID_HOME
ENV ANDROID_NDK_HOME $ANDROID_HOME/ndk-bundle
ENV PATH $ANDROID_HOME/tools/bin:$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION:$PATH
# Install Android SDK components
RUN echo "y" | sdkmanager \
"ndk-bundle" \
"lldb;3.1" \
"cmake;3.6.4111459" \
"extras;google;m2repository" \
"platform-tools" \
"platforms;android-$PLATFORM_VERSION" \
"build-tools;$BUILD_TOOLS_VERSION"
# Add release helper
COPY release /usr/local/bin/release
# Build directory
ENV SRC /src
RUN mkdir $SRC
WORKDIR $SRC
RUN echo "sdk.dir=$ANDROID_HOME" > local.properties
RUN echo "ndk.dir=$ANDROID_HOME" > local.properties
CMD ["./gradlew", "build"]

66
ndk/release

@ -0,0 +1,66 @@
#!/bin/sh
set -e
BUILT_APK=none
ALIGNED_APK=app/build/outputs/apk/release/app-release-unsigned-aligned.apk
SIGNED_APK=app/build/outputs/apk/release/app-release.apk
# Ensure directory exists
mkdir -p app/build/outputs/apk/release/
TEMP_DIR="$(mktemp -d)"
TEMP_STORE_FILE="$TEMP_DIR/store.jks"
if [ -z "$STORE_FILE" ] || [ -z "$STORE_PASSWORD" ] || [ -z "$KEY_ALIAS" ]; then
echo "STORE_FILE, STORE_PASSWORD or KEY_ALIAS are not configured secrets. Aborting..."
exit 1
fi
echo
echo "Reading STORE_FILE from environment"
echo $STORE_FILE | xxd -ps -r > $TEMP_STORE_FILE
# The following file is not required for the following process
# but I'm gonna leave it here anyway
echo > keystore.properties << EOF
storeFile=$TEMP_STORE_FILE
storePassword=$STORE_PASSWORD
keyAlias=$KEY_ALIAS
EOF
echo
echo "I think you're lazy so we will build a unsigned release APK and then sign it manually,"
echo "rather than using the gradle process."
echo
echo "Building unsigned release APK"
set -x
./gradlew assembleRelease
set +x
BUILT_APK=$(find . -name "*.apk")
echo
echo "Doing zipalign"
set -x
zipalign -v -p 4 $BUILT_APK $ALIGNED_APK
set +x
echo
echo "Signing"
set -x
apksigner sign \
--ks $TEMP_STORE_FILE \
--ks-pass pass:$STORE_PASSWORD \
--ks-key-alias $KEY_ALIAS \
--out $SIGNED_APK \
$ALIGNED_APK
set +x
echo
echo "Verifying"
set -x
apksigner verify $SIGNED_APK
set +x
echo "Done!"
Loading…
Cancel
Save