@@ -14,7 +14,7 @@ DOCKER_IMAGE=tailscale-android-build-amd64-191124
14
14
export TS_USE_TOOLCHAIN =1
15
15
16
16
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
18
18
19
19
DEBUG_APK =tailscale-debug.apk
20
20
RELEASE_AAB =tailscale-release.aab
@@ -151,22 +151,51 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
151
151
$(GOBIN ) /gobind : go.mod go.sum
152
152
./tool/go install golang.org/x/mobile/cmd/gobind
153
153
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
156
160
$(GOBIN ) /gomobile bind -target android -androidapi 26 \
157
161
-tags " $$ (./build-tags.sh)" \
158
162
-ldflags " $$ (./version-ldflags.sh)" \
159
163
-o $@ ./libtailscale
160
164
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
167
189
168
190
.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"
170
199
171
200
#
172
201
# Utility tasks:
@@ -207,7 +236,7 @@ androidpath:
207
236
@echo ' export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
208
237
209
238
.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
211
240
source tailscale.version && git tag -a " $$ {VERSION_LONG}" -m " OSS and Version updated to $$ {VERSION_LONG}"
212
241
213
242
0 commit comments