Skip to content

Commit

Permalink
Update to NDK r19
Browse files Browse the repository at this point in the history
Standalone toolchains are no longer required. This should speed up builds and decrease space required for building this app.

Fix shadowsocks#2022.
  • Loading branch information
Mygod committed Dec 26, 2018
1 parent 4199007 commit e005c81
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 52 deletions.
1 change: 1 addition & 0 deletions .circleci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ARG ndk_version=android-ndk-r19-beta2
FROM circleci/android:api-28-ndk

RUN \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A [shadowsocks](http://shadowsocks.org) client for Android, written in Kotlin.
* JDK 1.8
* Go 1.11+
* Android SDK
- Android NDK r16+
- Android NDK r19+

### BUILD

Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {

externalNativeBuild {
ndkBuild {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
arguments "-j${Runtime.runtime.availableProcessors()}"
}
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/overture/clean.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEPS=$DIR/.deps

rm -rf $DEPS
rm -rf $DIR/go/bin
rm -rf $DIR/.deps
rm -rf $DIR/bin

echo "Successfully clean overture"
58 changes: 17 additions & 41 deletions core/src/overture/make.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,18 @@ function try () {
}

[ -z "$ANDROID_NDK_HOME" ] && ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MIN_API=$1
TARGET=$DIR/bin
DEPS=$DIR/.deps

ANDROID_ARM_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-arm
ANDROID_ARM64_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-arm64
ANDROID_X86_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-x86

ANDROID_ARM_CC=$ANDROID_ARM_TOOLCHAIN/bin/arm-linux-androideabi-clang
ANDROID_ARM_STRIP=$ANDROID_ARM_TOOLCHAIN/bin/arm-linux-androideabi-strip

ANDROID_ARM64_CC=$ANDROID_ARM64_TOOLCHAIN/bin/aarch64-linux-android-clang
ANDROID_ARM64_STRIP=$ANDROID_ARM64_TOOLCHAIN/bin/aarch64-linux-android-strip

ANDROID_X86_CC=$ANDROID_X86_TOOLCHAIN/bin/i686-linux-android-clang
ANDROID_X86_STRIP=$ANDROID_X86_TOOLCHAIN/bin/i686-linux-android-strip

try mkdir -p $DEPS $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a

if [ ! -f "$ANDROID_ARM_CC" ]; then
echo "Make standalone toolchain for ARM arch"
$ANDROID_NDK_HOME/build/tools/make_standalone_toolchain.py --arch arm \
--api $MIN_API --install-dir $ANDROID_ARM_TOOLCHAIN
fi

if [ ! -f "$ANDROID_ARM64_CC" ]; then
echo "Make standalone toolchain for ARM64 arch"
$ANDROID_NDK_HOME/build/tools/make_standalone_toolchain.py --arch arm64 \
--api $MIN_API --install-dir $ANDROID_ARM64_TOOLCHAIN
fi

if [ ! -f "$ANDROID_X86_CC" ]; then
echo "Make standalone toolchain for X86 arch"
$ANDROID_NDK_HOME/build/tools/make_standalone_toolchain.py --arch x86 \
--api $MIN_API --install-dir $ANDROID_X86_TOOLCHAIN
fi
try mkdir -p $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a $TARGET/x86_64

export GOPATH=$DIR

if [ ! -f "$TARGET/armeabi-v7a/liboverture.so" ] || [ ! -f "$TARGET/arm64-v8a/liboverture.so" ] ||
[ ! -f "$TARGET/x86/liboverture.so" ]; then
[ ! -f "$TARGET/x86/liboverture.so" ] || [ ! -f "$TARGET/x86_64/liboverture.so" ]; then

pushd $GOPATH/src/github.com/shadowsocks/overture/main

Expand All @@ -56,25 +25,32 @@ if [ ! -f "$TARGET/armeabi-v7a/liboverture.so" ] || [ ! -f "$TARGET/arm64-v8a/li

echo "Cross compile overture for arm"
if [ ! -f "$TARGET/armeabi-v7a/liboverture.so" ]; then
try env CGO_ENABLED=1 CC=$ANDROID_ARM_CC GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w"
try $ANDROID_ARM_STRIP main
try env CGO_ENABLED=1 CC=$TOOLCHAIN/armv7a-linux-androideabi${MIN_API}-clang GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w"
try $TOOLCHAIN/arm-linux-androideabi-strip main
try mv main $TARGET/armeabi-v7a/liboverture.so
fi

echo "Cross compile overture for arm64"
if [ ! -f "$TARGET/arm64-v8a/liboverture.so" ]; then
try env CGO_ENABLED=1 CC=$ANDROID_ARM64_CC GOOS=android GOARCH=arm64 go build -ldflags="-s -w"
try $ANDROID_ARM64_STRIP main
try env CGO_ENABLED=1 CC=$TOOLCHAIN/aarch64-linux-android${MIN_API}-clang GOOS=android GOARCH=arm64 go build -ldflags="-s -w"
try $TOOLCHAIN/aarch64-linux-android-strip main
try mv main $TARGET/arm64-v8a/liboverture.so
fi

echo "Cross compile overture for x86"
echo "Cross compile overture for 386"
if [ ! -f "$TARGET/x86/liboverture.so" ]; then
try env CGO_ENABLED=1 CC=$ANDROID_X86_CC GOOS=android GOARCH=386 go build -ldflags="-s -w"
try $ANDROID_X86_STRIP main
try env CGO_ENABLED=1 CC=$TOOLCHAIN/i686-linux-android${MIN_API}-clang GOOS=android GOARCH=386 go build -ldflags="-s -w"
try $TOOLCHAIN/i686-linux-android-strip main
try mv main $TARGET/x86/liboverture.so
fi

echo "Cross compile overture for amd64"
if [ ! -f "$TARGET/x86_64/liboverture.so" ]; then
try env CGO_ENABLED=1 CC=$TOOLCHAIN/x86_64-linux-android${MIN_API}-clang GOOS=android GOARCH=amd64 go build -ldflags="-s -w"
try $TOOLCHAIN/x86_64-linux-android-strip main
try mv main $TARGET/x86_64/liboverture.so
fi

popd

fi
Expand Down
4 changes: 1 addition & 3 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ android {
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a', 'x86'
universalApk true
}
}
Expand Down Expand Up @@ -72,7 +70,7 @@ repositories {

apply plugin: 'com.google.gms.google-services'

ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3]
ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3, x86_64: 4]
if (getCurrentFlavor() == 'release') android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def offset = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
Expand Down
2 changes: 2 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ release=$1
cp mobile/build/outputs/apk/release/mobile-armeabi-v7a-release.apk shadowsocks-armeabi-v7a-${release}.apk
cp mobile/build/outputs/apk/release/mobile-arm64-v8a-release.apk shadowsocks-arm64-v8a-${release}.apk
cp mobile/build/outputs/apk/release/mobile-x86-release.apk shadowsocks-x86-${release}.apk
cp mobile/build/outputs/apk/release/mobile-x86_64-release.apk shadowsocks-x86_64-${release}.apk
cp mobile/build/outputs/apk/release/mobile-universal-release.apk shadowsocks--universal-${release}.apk
cp tv/build/outputs/apk/release/tv-armeabi-v7a-release.apk shadowsocks-tv-armeabi-v7a-${release}.apk
cp tv/build/outputs/apk/release/tv-arm64-v8a-release.apk shadowsocks-tv-arm64-v8a-${release}.apk
cp tv/build/outputs/apk/release/tv-x86-release.apk shadowsocks-tv-x86-${release}.apk
cp tv/build/outputs/apk/release/tv-x86_64-release.apk shadowsocks-tv-x86_64-${release}.apk
cp tv/build/outputs/apk/release/tv-universal-release.apk shadowsocks-tv--universal-${release}.apk
4 changes: 1 addition & 3 deletions tv/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ android {
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a', 'x86'
universalApk true
}
}
Expand All @@ -61,7 +59,7 @@ dependencies {

apply plugin: 'com.google.gms.google-services'

ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3]
ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3, x86_64: 4]
if (getCurrentFlavor() == 'release') android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def offset = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
Expand Down

0 comments on commit e005c81

Please sign in to comment.