13
13
DOCKER_IMAGE =tailscale-android-build-amd64-191124
14
14
export TS_USE_TOOLCHAIN =1
15
15
16
+ NDK_ROOT := $(ANDROID_HOME ) /ndk/23.1.7779620
17
+ STRIP_TOOL := $(NDK_ROOT ) /toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objcopy
18
+
16
19
DEBUG_APK =tailscale-debug.apk
17
20
RELEASE_AAB =tailscale-release.aab
18
21
RELEASE_TV_AAB =tailscale-tv-release.aab
19
22
LIBTAILSCALE =android/libs/libtailscale.aar
23
+ UNSTRIPPED_LIB = $(LIBTAILSCALE:.aar=_unstripped.aar )
20
24
# Extract the version code from build.gradle.
21
25
ifeq ($(shell uname) ,Linux)
22
26
ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip"
@@ -89,8 +93,29 @@ export GOROOT := # Unset
89
93
# Android Builds:
90
94
#
91
95
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
+
107
+ .PHONY : print-aar-contents
108
+ print-aar-contents : $(UNSTRIPPED_AAR )
109
+ @echo " Contents of $( UNSTRIPPED_AAR) :"
110
+ unzip -l $(UNSTRIPPED_AAR )
111
+
112
+ .PHONY : list-android-libs
113
+ list-android-libs :
114
+ @echo " Listing contents of android/libs:"
115
+ ls -l android/libs
116
+
92
117
.PHONY : apk
93
- apk : $(DEBUG_APK ) # # Build the debug APK
118
+ apk: $(DEBUG_APK ) # # Build the debug APK
94
119
95
120
.PHONY : tailscale-debug
96
121
tailscale-debug : $(DEBUG_APK ) # # Build the debug APK
@@ -109,7 +134,7 @@ release-tv: jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB
109
134
.PHONY : gradle-dependencies
110
135
gradle-dependencies : $(shell find android -type f -not -path "android/build/* " -not -path '* /.* ') $(LIBTAILSCALE ) tailscale.version
111
136
112
- $(DEBUG_APK ) : version gradle-dependencies
137
+ $(DEBUG_APK ) : libtailscale debug-symbols version gradle-dependencies print-aar-contents
113
138
(cd android && ./gradlew test assembleDebug)
114
139
install -C android/build/outputs/apk/debug/android-debug.apk $@
115
140
@@ -147,14 +172,61 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
147
172
$(GOBIN ) /gobind : go.mod go.sum
148
173
./tool/go install golang.org/x/mobile/cmd/gobind
149
174
150
- $(LIBTAILSCALE ) : Makefile android/libs $(shell find libtailscale -name * .go) go.mod go.sum $(GOBIN ) /gomobile tailscale.version
175
+ LIBTAILSCALE_AAR := android/libs/libtailscale.aar
176
+ UNSTRIPPED_AAR := android/libs/libtailscale_unstripped.aar
177
+ ARM64_SO_PATH := jni/arm64-v8a/libgojni.so
178
+
179
+ # Build the unstripped AAR.
180
+ $(UNSTRIPPED_AAR ) : Makefile android/libs $(shell find libtailscale -name * .go) go.mod go.sum $(GOBIN ) /gomobile tailscale.version
151
181
$(GOBIN ) /gomobile bind -target android -androidapi 26 \
152
182
-tags " $$ (./build-tags.sh)" \
153
- -ldflags " -w $$ (./version-ldflags.sh)" \
183
+ -ldflags " $$ (./version-ldflags.sh)" \
154
184
-o $@ ./libtailscale
185
+ @echo " Generated unstripped AAR: $@ "
186
+
187
+ # Extract the .so file from the unstripped AAR.
188
+ libgojni.so.unstripped :
189
+ @echo " Extracting libgojni.so from unstripped AAR..."
190
+ @if unzip -p $(UNSTRIPPED_AAR ) " jni/arm64-v8a/libgojni.so" > libgojni.so.unstripped; then \
191
+ echo " Found arm64-v8a libgojni.so" ; \
192
+ elif unzip -p $(UNSTRIPPED_AAR ) " jni/armeabi-v7a/libgojni.so" > libgojni.so.unstripped; then \
193
+ echo " Found armeabi-v7a libgojni.so" ; \
194
+ else \
195
+ echo " Neither 'jni/arm64-v8a/libgojni.so' nor 'jni/armeabi-v7a/libgojni.so' was found." ; \
196
+ echo " Listing contents of $( UNSTRIPPED_AAR) :" ; \
197
+ unzip -l $(UNSTRIPPED_AAR ) ; \
198
+ exit 1; \
199
+ fi
200
+
201
+ # Generate the debug symbol file from the extracted .so file.
202
+ libgojni.so.debug : libgojni.so.unstripped
203
+ @echo " Extracting debug symbols from libgojni.so..."
204
+ $(STRIP_TOOL ) --only-keep-debug libgojni.so.unstripped libgojni.so.debug
205
+
206
+ # Generate the stripped .so file from the extracted file.
207
+ libgojni.so.stripped : libgojni.so.unstripped
208
+ @echo " Stripping debug symbols from libgojni.so..."
209
+ $(STRIP_TOOL ) --strip-debug libgojni.so.unstripped libgojni.so.stripped
210
+
211
+ # Repackage the AAR with the stripped .so file.
212
+ $(LIBTAILSCALE_AAR ) : libgojni.so.stripped $(UNSTRIPPED_AAR )
213
+ @echo " Repackaging AAR with stripped libgojni.so..."
214
+ rm -rf temp_aar
215
+ mkdir temp_aar
216
+ unzip $(UNSTRIPPED_AAR ) -d temp_aar
217
+ cp libgojni.so.stripped temp_aar/$(ARM64_SO_PATH )
218
+ (cd temp_aar && zip -r ../$( LIBTAILSCALE_AAR) .)
219
+ rm -rf temp_aar
155
220
156
221
.PHONY : libtailscale
157
- libtailscale : $(LIBTAILSCALE ) # # Build the libtailscale AAR
222
+ libtailscale : $(LIBTAILSCALE_AAR ) # # Build the stripped libtailscale AAR
223
+
224
+ .PHONY : debug-symbols
225
+ debug-symbols : libgojni.so.debug
226
+
227
+ .PHONY : all
228
+ all : libtailscale debug-symbols
229
+ @echo " Build complete: Stripped AAR is $( LIBTAILSCALE_AAR) and debug symbols are in libgojni.so.debug"
158
230
159
231
#
160
232
# Utility tasks:
@@ -195,7 +267,7 @@ androidpath:
195
267
@echo ' export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
196
268
197
269
.PHONY : tag_release
198
- tag_release : tailscale.version # # Tag the current commit with the current version
270
+ tag_release : debug-symbols tailscale.version # # Tag the current commit with the current version and generate debug symbols
199
271
source tailscale.version && git tag -a " $$ {VERSION_LONG}" -m " OSS and Version updated to $$ {VERSION_LONG}"
200
272
201
273
0 commit comments