Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions build-android-lib.sh
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
#!/bin/bash
# Script to build NetBird mobile bindings using gomobile
# Usage: ./script.sh [version]
# - If a version is provided, it will be used.
# - If a version is provided, it will be used (with leading 'v' stripped if present).
# - If no version is provided:
# * Uses the latest Git tag if available.
# * Uses the latest Git tag if available (with leading 'v' stripped if present).
# * Otherwise, defaults to "dev-<short-hash>".
# - When running in GitHub Actions, uses "ci-<short-hash>" instead of "dev-<short-hash>".

set -e
set -euo pipefail

app_path=$(pwd)

# Normalize semantic versions to drop a leading 'v' (e.g., v1.2.3 -> 1.2.3).
# Only strips if the string starts with 'v' followed by a digit, so it won't affect
# dev/ci strings or other non-semver values.
normalize_version() {
local ver="$1"
if [[ "$ver" =~ ^v[0-9] ]]; then
ver="${ver#v}"
fi
echo "$ver"
}

get_version() {
if [ -n "$1" ]; then
echo "$1"
if [ -n "${1:-}" ]; then
normalize_version "$1"
return
fi

# Try to get an exact tag
local tag=$(git describe --tags --exact-match 2>/dev/null || true)
local tag
tag=$(git describe --tags --exact-match 2>/dev/null || true)

if [ -n "$tag" ]; then
echo "$tag"
normalize_version "$tag"
return
fi

# Fallback to "<prefix>-<short-hash>"
local short_hash=$(git rev-parse --short HEAD)
local short_hash
short_hash=$(git rev-parse --short HEAD)

if [ "$GITHUB_ACTIONS" == "true" ]; then
local new_version="ci-$short_hash"
local new_version
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
new_version="ci-$short_hash"
else
local new_version="dev-$short_hash"
new_version="dev-$short_hash"
fi

echo "$new_version"
}


cd netbird

# Get version using the function
version=$(get_version "$1")
version=$(get_version "${1:-}")
echo "Using version: $version"

gomobile init

CGO_ENABLED=0 gomobile bind \
-o $app_path/gomobile/netbird.aar \
-o "$app_path/gomobile/netbird.aar" \
-javapkg=io.netbird.gomobile \
-ldflags="-checklinkname=0 -X golang.zx2c4.com/wireguard/ipc.socketDirectory=/data/data/io.netbird.client/cache/wireguard -X github.com/netbirdio/netbird/version.version=$version" \
$(pwd)/client/android
"$(pwd)/client/android"

cd - > /dev/null
Loading