Skip to content

Commit dcb8688

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 6a3342e commit dcb8688

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

.github/workflows/android.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ jobs:
2929
# Clean should essentially be a no-op, but make sure that it works.
3030
- name: Clean
3131
run: make clean
32+
33+
- name: print android lib
34+
run: make list-android-libs
35+
36+
- name: print working dir
37+
run: make print-working-dir
38+
39+
- name: debug unstripped
40+
run: make debug-unstripped
3241

3342
- name: Build APKs
3443
run: make tailscale-debug.apk

.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: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
DOCKER_IMAGE=tailscale-android-build-amd64-191124
1414
export TS_USE_TOOLCHAIN=1
1515

16+
NDK_ROOT := $(ANDROID_HOME)/ndk/23.1.7779620
17+
STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objcopy
18+
1619
DEBUG_APK=tailscale-debug.apk
1720
RELEASE_AAB=tailscale-release.aab
1821
RELEASE_TV_AAB=tailscale-tv-release.aab
1922
LIBTAILSCALE=android/libs/libtailscale.aar
23+
UNSTRIPPED_LIB = $(LIBTAILSCALE:.aar=_unstripped.aar)
2024
# Extract the version code from build.gradle.
2125
ifeq ($(shell uname),Linux)
2226
ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip"
@@ -89,8 +93,33 @@ export GOROOT := # Unset
8993
# Android Builds:
9094
#
9195

96+
.PHONY: print-info
97+
print-info:
98+
@echo "Running: $(shell uname -a)"
99+
@echo "CI environment: $$CI"
100+
@echo "Runner OS: $$RUNNER_OS"
101+
102+
.PHONY: print-working-dir
103+
print-working-dir:
104+
@echo "Current directory: $(shell pwd)"
105+
106+
.PHONY: debug-unstripped
107+
debug-unstripped: $(UNSTRIPPED_AAR)
108+
@echo "Contents of android/libs:"; ls -l android/libs
109+
110+
111+
.PHONY: print-aar-contents
112+
print-aar-contents: $(UNSTRIPPED_AAR)
113+
@echo "Contents of $(UNSTRIPPED_AAR):"
114+
unzip -l $(UNSTRIPPED_AAR)
115+
116+
.PHONY: list-android-libs
117+
list-android-libs: android/libs
118+
@echo "Listing contents of android/libs:"
119+
ls -l android/libs
120+
92121
.PHONY: apk
93-
apk: $(DEBUG_APK) ## Build the debug APK
122+
apk: $(DEBUG_APK) ## Build the debug APK
94123

95124
.PHONY: tailscale-debug
96125
tailscale-debug: $(DEBUG_APK) ## Build the debug APK
@@ -109,7 +138,7 @@ release-tv: jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB
109138
.PHONY: gradle-dependencies
110139
gradle-dependencies: $(shell find android -type f -not -path "android/build/*" -not -path '*/.*') $(LIBTAILSCALE) tailscale.version
111140

112-
$(DEBUG_APK): version gradle-dependencies
141+
$(DEBUG_APK): libtailscale debug-symbols version gradle-dependencies print-aar-contents
113142
(cd android && ./gradlew test assembleDebug)
114143
install -C android/build/outputs/apk/debug/android-debug.apk $@
115144

@@ -128,7 +157,7 @@ tailscale-test.apk: version gradle-dependencies
128157
install -C ./android/build/outputs/apk/androidTest/applicationTest/android-applicationTest-androidTest.apk $@
129158

130159
tailscale.version: go.mod go.sum $(wildcard .git/HEAD)
131-
$(shell ./tool/go run tailscale.com/cmd/mkversion > tailscale.version)
160+
@bash -c "./tool/go run tailscale.com/cmd/mkversion > tailscale.version"
132161

133162
.PHONY: version
134163
version: tailscale.version ## print the current version information
@@ -147,14 +176,61 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
147176
$(GOBIN)/gobind: go.mod go.sum
148177
./tool/go install golang.org/x/mobile/cmd/gobind
149178

150-
$(LIBTAILSCALE): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
179+
LIBTAILSCALE_AAR := android/libs/libtailscale.aar
180+
UNSTRIPPED_AAR := android/libs/libtailscale_unstripped.aar
181+
ARM64_SO_PATH := jni/arm64-v8a/libgojni.so
182+
183+
# Build the unstripped AAR.
184+
$(UNSTRIPPED_AAR): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
151185
$(GOBIN)/gomobile bind -target android -androidapi 26 \
152186
-tags "$$(./build-tags.sh)" \
153-
-ldflags "-w $$(./version-ldflags.sh)" \
187+
-ldflags "$$(./version-ldflags.sh)" \
154188
-o $@ ./libtailscale
189+
@echo "Generated unstripped AAR: $@"
190+
191+
# Extract the .so file from the unstripped AAR.
192+
libgojni.so.unstripped:
193+
@echo "Extracting libgojni.so from unstripped AAR..."
194+
@if unzip -p $(UNSTRIPPED_AAR) "jni/arm64-v8a/libgojni.so" > libgojni.so.unstripped; then \
195+
echo "Found arm64-v8a libgojni.so"; \
196+
elif unzip -p $(UNSTRIPPED_AAR) "jni/armeabi-v7a/libgojni.so" > libgojni.so.unstripped; then \
197+
echo "Found armeabi-v7a libgojni.so"; \
198+
else \
199+
echo "Neither 'jni/arm64-v8a/libgojni.so' nor 'jni/armeabi-v7a/libgojni.so' was found."; \
200+
echo "Listing contents of $(UNSTRIPPED_AAR):"; \
201+
unzip -l $(UNSTRIPPED_AAR); \
202+
exit 1; \
203+
fi
204+
205+
# Generate the debug symbol file from the extracted .so file.
206+
libgojni.so.debug: libgojni.so.unstripped
207+
@echo "Extracting debug symbols from libgojni.so..."
208+
$(STRIP_TOOL) --only-keep-debug libgojni.so.unstripped libgojni.so.debug
209+
210+
# Generate the stripped .so file from the extracted file.
211+
libgojni.so.stripped: libgojni.so.unstripped
212+
@echo "Stripping debug symbols from libgojni.so..."
213+
$(STRIP_TOOL) --strip-debug libgojni.so.unstripped libgojni.so.stripped
214+
215+
# Repackage the AAR with the stripped .so file.
216+
$(LIBTAILSCALE_AAR): libgojni.so.stripped $(UNSTRIPPED_AAR)
217+
@echo "Repackaging AAR with stripped libgojni.so..."
218+
rm -rf temp_aar
219+
mkdir temp_aar
220+
unzip $(UNSTRIPPED_AAR) -d temp_aar
221+
cp libgojni.so.stripped temp_aar/$(ARM64_SO_PATH)
222+
(cd temp_aar && zip -r ../$(LIBTAILSCALE_AAR) .)
223+
rm -rf temp_aar
155224

156225
.PHONY: libtailscale
157-
libtailscale: $(LIBTAILSCALE) ## Build the libtailscale AAR
226+
libtailscale: $(LIBTAILSCALE_AAR) ## Build the stripped libtailscale AAR
227+
228+
.PHONY: debug-symbols
229+
debug-symbols: libgojni.so.debug
230+
231+
.PHONY: all
232+
all: libtailscale debug-symbols
233+
@echo "Build complete: Stripped AAR is $(LIBTAILSCALE_AAR) and debug symbols are in libgojni.so.debug"
158234

159235
#
160236
# Utility tasks:
@@ -195,7 +271,7 @@ androidpath:
195271
@echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
196272

197273
.PHONY: tag_release
198-
tag_release: tailscale.version ## Tag the current commit with the current version
274+
tag_release: debug-symbols tailscale.version ## Tag the current commit with the current version and generate debug symbols
199275
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
200276

201277

0 commit comments

Comments
 (0)