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,18 @@ 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-aar-contents
103
+ print-aar-contents :
104
+ unzip -l $(UNSTRIPPED_AAR )
105
+
92
106
.PHONY : apk
93
- apk : $(DEBUG_APK ) # # Build the debug APK
107
+ apk: $(DEBUG_APK ) # # Build the debug APK
94
108
95
109
.PHONY : tailscale-debug
96
110
tailscale-debug : $(DEBUG_APK ) # # Build the debug APK
@@ -109,7 +123,7 @@ release-tv: jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB
109
123
.PHONY : gradle-dependencies
110
124
gradle-dependencies : $(shell find android -type f -not -path "android/build/* " -not -path '* /.* ') $(LIBTAILSCALE ) tailscale.version
111
125
112
- $(DEBUG_APK ) : version gradle-dependencies
126
+ $(DEBUG_APK ) : print-aar-contents libtailscale debug-symbols version print-aar-contents gradle-dependencies
113
127
(cd android && ./gradlew test assembleDebug)
114
128
install -C android/build/outputs/apk/debug/android-debug.apk $@
115
129
@@ -147,14 +161,51 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
147
161
$(GOBIN ) /gobind : go.mod go.sum
148
162
./tool/go install golang.org/x/mobile/cmd/gobind
149
163
150
- $(LIBTAILSCALE ) : Makefile android/libs $(shell find libtailscale -name * .go) go.mod go.sum $(GOBIN ) /gomobile tailscale.version
164
+ LIBTAILSCALE_AAR := android/libs/libtailscale.aar
165
+ UNSTRIPPED_AAR := android/libs/libtailscale_unstripped.aar
166
+ ARM64_SO_PATH := jni/arm64-v8a/libgojni.so
167
+
168
+ # Build the unstripped AAR.
169
+ $(UNSTRIPPED_AAR ) : Makefile android/libs $(shell find libtailscale -name * .go) go.mod go.sum $(GOBIN ) /gomobile tailscale.version
151
170
$(GOBIN ) /gomobile bind -target android -androidapi 26 \
152
171
-tags " $$ (./build-tags.sh)" \
153
- -ldflags " -w $$ (./version-ldflags.sh)" \
172
+ -ldflags " $$ (./version-ldflags.sh)" \
154
173
-o $@ ./libtailscale
155
174
175
+ # Extract the .so file from the unstripped AAR.
176
+ libgojni.so.unstripped :
177
+ @echo " Extracting libgojni.so from unstripped AAR..."
178
+ unzip -p $(UNSTRIPPED_AAR ) " $( ARM64_SO_PATH) " > libgojni.so.unstripped
179
+
180
+ # Generate the debug symbol file from the extracted .so file.
181
+ libgojni.so.debug : libgojni.so.unstripped
182
+ @echo " Extracting debug symbols from libgojni.so..."
183
+ $(STRIP_TOOL ) --only-keep-debug libgojni.so.unstripped libgojni.so.debug
184
+
185
+ # Generate the stripped .so file from the extracted file.
186
+ libgojni.so.stripped : libgojni.so.unstripped
187
+ @echo " Stripping debug symbols from libgojni.so..."
188
+ $(STRIP_TOOL ) --strip-debug libgojni.so.unstripped libgojni.so.stripped
189
+
190
+ # Repackage the AAR with the stripped .so file.
191
+ $(LIBTAILSCALE_AAR ) : libgojni.so.stripped $(UNSTRIPPED_AAR )
192
+ @echo " Repackaging AAR with stripped libgojni.so..."
193
+ rm -rf temp_aar
194
+ mkdir temp_aar
195
+ unzip $(UNSTRIPPED_AAR ) -d temp_aar
196
+ cp libgojni.so.stripped temp_aar/$(ARM64_SO_PATH )
197
+ (cd temp_aar && zip -r ../$( LIBTAILSCALE_AAR) .)
198
+ rm -rf temp_aar
199
+
156
200
.PHONY : libtailscale
157
- libtailscale : $(LIBTAILSCALE ) # # Build the libtailscale AAR
201
+ libtailscale : $(LIBTAILSCALE_AAR ) # # Build the stripped libtailscale AAR
202
+
203
+ .PHONY : debug-symbols
204
+ debug-symbols : libgojni.so.debug
205
+
206
+ .PHONY : all
207
+ all : libtailscale debug-symbols
208
+ @echo " Build complete: Stripped AAR is $( LIBTAILSCALE_AAR) and debug symbols are in libgojni.so.debug"
158
209
159
210
#
160
211
# Utility tasks:
@@ -195,7 +246,7 @@ androidpath:
195
246
@echo ' export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
196
247
197
248
.PHONY : tag_release
198
- tag_release : tailscale.version # # Tag the current commit with the current version
249
+ tag_release : debug-symbols tailscale.version # # Tag the current commit with the current version and generate debug symbols
199
250
source tailscale.version && git tag -a " $$ {VERSION_LONG}" -m " OSS and Version updated to $$ {VERSION_LONG}"
200
251
201
252
0 commit comments