Skip to content

Commit a99275b

Browse files
committed
Makefile: make unstripped libtailscale and debug symbols
- Added Makefile targets to build an unstripped version of the libtailscale AAR. - Extracted the native .so (libgojni.so) from the unstripped AAR. - Generated a debug symbols file (libgojni.so.debug) using llvm-objcopy with --only-keep-debug. - Stripped the native library (libgojni.so.stripped) with --strip-debug and repackaged the final AAR. This allows the build chain to produce a stripped AAR for the app and a separate debug symbols file that can be uploaded to Google Play for crash deobfuscation. Signed-off-by: kari-ts <[email protected]> Updates tailscale/tailscale#15210
1 parent 2e71b41 commit a99275b

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ tailscale.jks
3535
.vscode
3636
.idea
3737

38+
# Native libraries
39+
*.stripped
40+
*.unstripped
41+
42+
# Debug symbols
43+
*.debug
44+
3845
libtailscale.aar
3946
libtailscale-sources.jar
4047
.DS_Store

Makefile

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DOCKER_IMAGE=tailscale-android-build-amd64-191124
1414
export TS_USE_TOOLCHAIN=1
1515

1616
NDK_ROOT := $(ANDROID_HOME)/ndk/23.1.7779620
17-
STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip
17+
STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objcopy
1818

1919
DEBUG_APK=tailscale-debug.apk
2020
RELEASE_AAB=tailscale-release.aab
@@ -151,22 +151,51 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
151151
$(GOBIN)/gobind: go.mod go.sum
152152
./tool/go install golang.org/x/mobile/cmd/gobind
153153

154-
# Build the unstripped version with full debug symbols.
155-
$(UNSTRIPPED_LIB): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
154+
LIBTAILSCALE_AAR := android/libs/libtailscale.aar
155+
UNSTRIPPED_AAR := android/libs/libtailscale_unstripped.aar
156+
ARM64_SO_PATH := jni/arm64-v8a/libgojni.so
157+
158+
# Build the unstripped AAR.
159+
$(UNSTRIPPED_AAR): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
156160
$(GOBIN)/gomobile bind -target android -androidapi 26 \
157161
-tags "$$(./build-tags.sh)" \
158162
-ldflags "$$(./version-ldflags.sh)" \
159163
-o $@ ./libtailscale
160164

161-
# Generate the final library by extracting debug symbols and stripping them.
162-
$(LIBTAILSCALE): $(UNSTRIPPED_LIB)
163-
@echo "Extracting debug symbols from $<..."
164-
$(STRIP_TOOL) --only-keep-debug $< -o $@.debug
165-
@echo "Stripping debug symbols from $<..."
166-
$(STRIP_TOOL) --strip-debug $< -o $@
165+
# Extract the .so file from the unstripped AAR.
166+
libgojni.so.unstripped:
167+
@echo "Extracting libgojni.so from unstripped AAR..."
168+
unzip -p $(UNSTRIPPED_AAR) "$(ARM64_SO_PATH)" > libgojni.so.unstripped
169+
170+
# Generate the debug symbol file from the extracted .so file.
171+
libgojni.so.debug: libgojni.so.unstripped
172+
@echo "Extracting debug symbols from libgojni.so..."
173+
$(STRIP_TOOL) --only-keep-debug libgojni.so.unstripped libgojni.so.debug
174+
175+
# Generate the stripped .so file from the extracted file.
176+
libgojni.so.stripped: libgojni.so.unstripped
177+
@echo "Stripping debug symbols from libgojni.so..."
178+
$(STRIP_TOOL) --strip-debug libgojni.so.unstripped libgojni.so.stripped
179+
180+
# Repackage the AAR with the stripped .so file.
181+
$(LIBTAILSCALE_AAR): libgojni.so.stripped $(UNSTRIPPED_AAR)
182+
@echo "Repackaging AAR with stripped libgojni.so..."
183+
rm -rf temp_aar
184+
mkdir temp_aar
185+
unzip $(UNSTRIPPED_AAR) -d temp_aar
186+
cp libgojni.so.stripped temp_aar/$(ARM64_SO_PATH)
187+
(cd temp_aar && zip -r ../$(LIBTAILSCALE_AAR) .)
188+
rm -rf temp_aar
167189

168190
.PHONY: libtailscale
169-
libtailscale: $(LIBTAILSCALE) ## Build the libtailscale AAR
191+
libtailscale: $(LIBTAILSCALE_AAR) ## Build the stripped libtailscale AAR
192+
193+
.PHONY: debug-symbols
194+
debug-symbols: libgojni.so.debug
195+
196+
.PHONY: all
197+
all: libtailscale debug-symbols
198+
@echo "Build complete: Stripped AAR is $(LIBTAILSCALE_AAR) and debug symbols are in libgojni.so.debug"
170199

171200
#
172201
# Utility tasks:
@@ -207,7 +236,7 @@ androidpath:
207236
@echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
208237

209238
.PHONY: tag_release
210-
tag_release: tailscale.version ## Tag the current commit with the current version
239+
tag_release: debug-symbols tailscale.version ## Tag the current commit with the current version and generate debug symbols
211240
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
212241

213242

0 commit comments

Comments
 (0)