storj/lib/uplink-gomobile/build.sh

65 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
# This script will build libuplink-android.aar library from scratch
# Required:
# * ANDROID_HOME set with NDK available
# * go
if [ -z "$ANDROID_HOME" ]
then
2019-10-17 16:39:34 +01:00
echo "\$ANDROID_HOME is not set" && exit 1
fi
2019-10-17 16:39:34 +01:00
if [ ! -d "$ANDROID_HOME/ndk-bundle" ]
then
echo "ANDROID NDK is not available" && exit 1
fi
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
2019-10-04 09:56:42 +01:00
# setup tmpdir for testfiles and cleanup
TMP=$(mktemp -d -t tmp.XXXXXXXXXX)
2019-10-17 16:39:34 +01:00
GOPATH_SYSTEM=$(go env GOPATH)
2019-10-04 09:56:42 +01:00
cleanup(){
2019-10-17 16:39:34 +01:00
if [ -z "$GOPATH_SYSTEM" ]
then
# cleanup pkg/mod directory
go clean -modcache
fi
2019-10-04 09:56:42 +01:00
rm -rf "$TMP"
}
trap cleanup EXIT
2019-10-04 09:56:42 +01:00
OUTPUT=$PWD
2019-10-17 16:39:34 +01:00
mkdir -p "$TMP/pkg/mod/" "$TMP/src/storj.io/storj/"
if [ -n "$GOPATH_SYSTEM" ]
then
# use this only if GOPATH is set
# link pkg/mod to avoid redownloading modules
ln -s $GOPATH_SYSTEM/pkg/mod/* "$TMP/pkg/mod/"
fi
# go knows where our gopath is
2019-10-04 09:56:42 +01:00
export GOPATH=$TMP
2019-10-04 09:56:42 +01:00
# symlink doesn't look to be working with gomobile
2019-10-17 16:39:34 +01:00
rsync -am --stats --exclude=".*" $SCRIPTDIR/../../* "$GOPATH/src/storj.io/storj/"
2019-10-04 09:56:42 +01:00
cd "$GOPATH/src/storj.io/storj"
2019-10-04 09:56:42 +01:00
go mod vendor
2019-10-04 09:56:42 +01:00
cp -r $GOPATH/src/storj.io/storj/vendor/* "$GOPATH/src"
2019-10-04 09:56:42 +01:00
# set go modules to default behavior
export GO111MODULE=off
go get golang.org/x/mobile/cmd/gomobile
2019-10-17 16:39:34 +01:00
# add gobind to PATH
export PATH=$GOPATH/bin:$PATH
2019-10-04 09:56:42 +01:00
2019-10-17 16:39:34 +01:00
$GOPATH/bin/gomobile init
2019-10-17 16:39:34 +01:00
$GOPATH/bin/gomobile bind -v -target android -o "$OUTPUT/libuplink-android.aar" -javapkg io.storj.libuplink storj.io/storj/lib/uplink-gomobile