Migrate to go mod

This commit is contained in:
Mygod 2019-01-18 09:45:25 +08:00
parent 4a838a399c
commit f7bf0b8e74
9 changed files with 43 additions and 81 deletions

View file

@ -12,9 +12,15 @@ jobs:
- run: git submodule update --init --recursive
- restore_cache:
key: jars-{{ checksum "build.gradle" }}
- restore_cache:
key: go
- run:
name: Run Build and Tests
command: ./gradlew assembleDebug check
- save_cache:
paths:
- ~/go
key: go
- save_cache:
paths:
- ~/.gradle

6
.gitmodules vendored
View file

@ -1,3 +1,3 @@
[submodule "app/src/v2ray-plugin"]
path = app/src/v2ray-plugin
url = https://github.com/madeye/v2ray-plugin
[submodule "app/src/main/go/v2ray-plugin"]
path = app/src/main/go/v2ray-plugin
url = https://github.com/shadowsocks/v2ray-plugin.git

4
app/.gitignore vendored
View file

@ -3,7 +3,3 @@
# no tests written yet
/src/androidTest
/src/test
/src/bin
/src/pkg
/src/src
/.deps

View file

@ -41,15 +41,15 @@ android {
universalApk true
}
}
sourceSets.main.jniLibs.srcDirs += new File(projectDir, "src/bin")
sourceSets.main.jniLibs.srcDirs += new File(projectDir, "build/go")
}
task goBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
println "Warning: Building on Windows is not supported"
} else {
executable "sh"
args "-c", "src/make.bash " + minSdkVersion
executable "/bin/bash"
args "go-build.bash", minSdkVersion
environment "ANDROID_HOME", android.sdkDirectory
environment "ANDROID_NDK_HOME", android.ndkDirectory
}

30
app/go-build.bash Normal file
View file

@ -0,0 +1,30 @@
#!/bin/bash
[[ -z "${ANDROID_NDK_HOME}" ]] && ANDROID_NDK_HOME="${ANDROID_HOME}/ndk-bundle"
TOOLCHAIN="$(find ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/* -maxdepth 1 -type d -print -quit)/bin"
ABIS=(armeabi-v7a arm64-v8a x86 x86_64)
GO_ARCHS=('arm GOARM=7' arm64 386 amd64)
CLANG_ARCHS=(armv7a-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android)
STRIP_ARCHS=(arm-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android)
MIN_API="$1"
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUT_DIR="$ROOT/build/go"
cd "$ROOT/src/main/go/v2ray-plugin"
BIN="libv2ray.so"
for i in "${!ABIS[@]}"; do
ABI="${ABIS[$i]}"
[[ -f "${OUT_DIR}/${ABI}/${BIN}" ]] && continue
echo "Build ${BIN} ${ABI}"
mkdir -p ${OUT_DIR}/${ABI} \
&& env \
CGO_ENABLED=1 CC="${TOOLCHAIN}/${CLANG_ARCHS[$i]}${MIN_API}-clang" \
GOOS=android GOARCH=${GO_ARCHS[$i]} \
go build -v -ldflags='-s -w' -o "${OUT_DIR}/unstripped" \
&& "${TOOLCHAIN}/${STRIP_ARCHS[$i]}-strip" "${OUT_DIR}/unstripped" -o "${OUT_DIR}/${ABI}/${BIN}" \
|| exit -1
rm "${OUT_DIR}/unstripped"
done
cd "$ROOT"

View file

@ -1,8 +0,0 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rm -rf $DIR/.deps
rm -rf $DIR/bin
echo "Successfully clean v2ray"

@ -0,0 +1 @@
Subproject commit d3c12013b948ed7177cb1cde41e23d50256e3ae4

View file

@ -1,62 +0,0 @@
#!/bin/bash
function try () {
"$@" || exit -1
}
[ -z "$ANDROID_NDK_HOME" ] && ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
TOOLCHAIN=$(find $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/* -maxdepth 1 -type d -print -quit)/bin
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MIN_API=$1
TARGET=$DIR/bin
try mkdir -p $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a $TARGET/x86_64
export GOPATH=$DIR
pushd $DIR/v2ray-plugin
if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ] || [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ] ||
[ ! -f "$TARGET/x86/libv2ray.so" ] || [ ! -f "$TARGET/x86_64/libv2ray.so" ]; then
echo "Get dependences for v2ray"
go get -v
echo "Cross compile v2ray for arm"
if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ]; then
try env CGO_ENABLED=1 CC=$TOOLCHAIN/armv7a-linux-androideabi${MIN_API}-clang GOOS=android GOARCH=arm GOARM=7 \
go build -ldflags="-s -w" -o client
try $TOOLCHAIN/arm-linux-androideabi-strip client
try mv client $TARGET/armeabi-v7a/libv2ray.so
fi
echo "Cross compile v2ray for arm64"
if [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ]; then
try env CGO_ENABLED=1 CC=$TOOLCHAIN/aarch64-linux-android${MIN_API}-clang GOOS=android GOARCH=arm64 \
go build -ldflags="-s -w" -o client
try $TOOLCHAIN/aarch64-linux-android-strip client
try mv client $TARGET/arm64-v8a/libv2ray.so
fi
echo "Cross compile v2ray for 386"
if [ ! -f "$TARGET/x86/libv2ray.so" ]; then
try env CGO_ENABLED=1 CC=$TOOLCHAIN/i686-linux-android${MIN_API}-clang GOOS=android GOARCH=386 \
go build -ldflags="-s -w" -o client
try $TOOLCHAIN/i686-linux-android-strip client
try mv client $TARGET/x86/libv2ray.so
fi
echo "Cross compile v2ray for amd64"
if [ ! -f "$TARGET/x86_64/libv2ray.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" -o client
try $TOOLCHAIN/x86_64-linux-android-strip client
try mv client $TARGET/x86_64/libv2ray.so
fi
popd
fi
echo "Successfully build v2ray"

@ -1 +0,0 @@
Subproject commit 1be661dbac71272443c0c69e0828b15f36152691