github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/bind/java/test.bash (about) 1 #!/usr/bin/env bash 2 # Copyright 2014 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 set -e 7 8 function die() { 9 echo "FAIL: $1" 10 exit 1 11 } 12 13 if [ ! -f test.bash ]; then 14 die 'test.bash must be run from $GOPATH/src/golang.org/x/mobile/bind/java' 15 fi 16 17 function cleanup() { 18 rm -rf "$ANDROID_APP" 19 } 20 21 if [ -z "$ANDROID_APP" ]; then 22 ANDROID_APP=`mktemp -d /tmp/android-java.XXXXX` || die 'failed to create a temporary directory' 23 echo "Temporary directory for test: $ANDROID_APP" 24 trap cleanup EXIT 25 fi 26 27 # Create an android project for test. 28 # TODO(hyangah): use android update lib-project if the $ANDROID_APP directory 29 # already exists. 30 android create lib-project -n BindJavaTest \ 31 -t "android-19" -p $ANDROID_APP -k go.testpkg -g -v 0.12.+ 32 33 # Add the necessary Java source files (Seq.java and app/Go.java)) in to the 34 # project directory. (go package) 35 mkdir -p $ANDROID_APP/src/main/java/go 36 ln -sf $PWD/Seq.java $ANDROID_APP/src/main/java/go 37 ln -sf $PWD/../../app/*.java $ANDROID_APP/src/main/java/go 38 39 # Add the testpkg java file (output of gobind -lang=java) necessary for SeqTest.java. 40 mkdir -p $ANDROID_APP/src/main/java/go/testpkg 41 ln -sf $PWD/testpkg/Testpkg.java $ANDROID_APP/src/main/java/go/testpkg 42 43 # Add the compiled jni shared library under src/main/jniLibs/armeabi directory. 44 mkdir -p $ANDROID_APP/src/main/jniLibs/armeabi 45 CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \ 46 go build -ldflags="-shared" \ 47 -o $ANDROID_APP/src/main/jniLibs/armeabi/libgojni.so \ 48 javatest.go 49 50 # Add the test file under androidTest directory. 51 mkdir -p $ANDROID_APP/src/androidTest/java/go 52 ln -sf $PWD/SeqTest.java $ANDROID_APP/src/androidTest/java/go 53 54 # Build the test apk. ($ANDROID_APP/build/outputs/apk). 55 cd $ANDROID_APP 56 57 # If there is no connected device, this will fail after creating the test apk. 58 # The apk is located in $ANDROID_APP/build/outputs/apk directory. 59 ./gradlew connectedAndroidTest && echo "PASS" 60 61 # TODO(hyangah): copy the gradle's test output directory in case of test failure? 62 63 # TODO(hyangah): gradlew build 64 # Currently build fails due to a lint error. Disable lint check or 65 # specify the minSdkVersion in gradle.build to avoid the lint error.