| 1 | #!/bin/bash |
| 2 | set -x -e |
| 3 | cd "$(dirname "$0")" |
| 4 | |
| 5 | if [[ "$1" == "--install" ]]; then |
| 6 | # install go > 1.24: |
| 7 | wget https://go.dev/dl/go1.24.1.linux-amd64.tar.gz |
| 8 | sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.24.1.linux-amd64.tar.gz |
| 9 | export PATH=$PATH:/usr/local/go/bin |
| 10 | export PATH=$PATH:~/go/bin |
| 11 | fi |
| 12 | |
| 13 | cd ../../cw_mweb/go |
| 14 | |
| 15 | if [[ "x$ANDROID_NDK_VERSION" == "x" ]]; |
| 16 | then |
| 17 | echo "ANDROID_NDK_VERSION is missing, please declare it before building" |
| 18 | echo "You have these versions installed on your system currently:" |
| 19 | ls ${ANDROID_HOME}/ndk/ | cat | awk '{ print "- " $1 }' |
| 20 | echo "echo > ~/.zprofile" |
| 21 | echo "echo 'export ANDROID_NDK_VERSION=..... > ~/.zprofile" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | export ANDROID_OUT=../android/src/main/jniLibs |
| 26 | export ANDROID_SDK="${HOME}/Library/Android/sdk" |
| 27 | export NDK_BIN="${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/$(uname | tr '[:upper:]' '[:lower:]')-x86_64/bin" |
| 28 | |
| 29 | # Compile for x86_64 architecture and place the binary file in the android/src/main/jniLibs/x86_64 folder |
| 30 | export CGO_LDFLAGS="-O2 -g -s -w -Wl,-z,max-page-size=16384" |
| 31 | |
| 32 | CGO_ENABLED=1 \ |
| 33 | GOOS=android \ |
| 34 | GOARCH=amd64 \ |
| 35 | CC=${NDK_BIN}/x86_64-linux-android21-clang \ |
| 36 | go build -v -buildmode=c-shared -o ${ANDROID_OUT}/x86_64/libmweb.so . |
| 37 | |
| 38 | # Compile for arm64 architecture and place the binary file in the android/src/main/jniLibs/arm64-v8a folder |
| 39 | CGO_ENABLED=1 \ |
| 40 | GOOS=android \ |
| 41 | GOARCH=arm64 \ |
| 42 | CC=${NDK_BIN}/aarch64-linux-android21-clang \ |
| 43 | go build -v -buildmode=c-shared -o ${ANDROID_OUT}/arm64-v8a/libmweb.so . |
| 44 | |
| 45 | # Compile for armv7a architecture and place the binary file in the android/src/main/jniLibs/armeabi-v7a folder |
| 46 | CGO_ENABLED=1 \ |
| 47 | GOOS=android \ |
| 48 | GOARCH=arm \ |
| 49 | CC=${NDK_BIN}/armv7a-linux-androideabi21-clang \ |
| 50 | go build -v -buildmode=c-shared -o ${ANDROID_OUT}/armeabi-v7a/libmweb.so . |
| 51 | cd ../ |
| 52 | dart run ffigen --config ffigen_config.yaml |