@@ -91,12 +91,6 @@ echo "Running native tests"
9191 go test ./...
9292)
9393
94- echo " Running Android unit tests"
95- (
96- cd " $project_dir "
97- ./gradlew testReleaseUnitTest
98- )
99-
10094# gomobile architecture names and their corresponding Android ABI names.
10195targets=(
10296 " arm64:arm64-v8a"
@@ -105,27 +99,59 @@ targets=(
10599 " 386:x86"
106100)
107101
102+ # A clean checkout has no app/libs/megaproxy.aar. Gradle resolves local AAR
103+ # dependencies while configuring Android unit tests, so build the first ABI
104+ # before invoking Gradle and reuse it for the first release APK below.
105+ first_target=" ${targets[0]} "
106+ first_go_arch=" ${first_target%%:* } "
107+ first_android_abi=" ${first_target##*: } "
108+ echo " Building initial native AAR for $first_android_abi "
109+ (
110+ cd " $project_dir /native"
111+ gomobile bind \
112+ -target=" android/$first_go_arch " \
113+ -androidapi 26 \
114+ -trimpath \
115+ -ldflags=" -s -w -buildid=" \
116+ -o ../app/libs/megaproxy.aar \
117+ ./mobile
118+ )
119+
120+ echo " Running Android unit tests"
121+ (
122+ cd " $project_dir "
123+ ./gradlew testReleaseUnitTest
124+ )
125+
108126for target in " ${targets[@]} " ; do
109127 go_arch=" ${target%%:* } "
110128 android_abi=" ${target##*: } "
111129 output_apk=" $MEGAPROXY_RELEASE_DIR /mega-proxy-v${version_name} -${android_abi} .apk"
112130
113- echo " Building optimized native AAR for $android_abi "
114- (
115- cd " $project_dir /native"
116- gomobile bind \
117- -target=" android/$go_arch " \
118- -androidapi 26 \
119- -trimpath \
120- -ldflags=" -s -w -buildid=" \
121- -o ../app/libs/megaproxy.aar \
122- ./mobile
123- )
131+ if [[ " $android_abi " == " $first_android_abi " ]]; then
132+ echo " Reusing initial native AAR for $android_abi "
133+ else
134+ echo " Building optimized native AAR for $android_abi "
135+ (
136+ cd " $project_dir /native"
137+ gomobile bind \
138+ -target=" android/$go_arch " \
139+ -androidapi 26 \
140+ -trimpath \
141+ -ldflags=" -s -w -buildid=" \
142+ -o ../app/libs/megaproxy.aar \
143+ ./mobile
144+ )
145+ fi
124146
125147 echo " Building and signing $android_abi APK"
126148 (
127149 cd " $project_dir "
128- ./gradlew clean assembleRelease
150+ # Keep clean and assemble in separate Gradle invocations. When both are
151+ # requested in one task graph, Gradle does not guarantee that clean has
152+ # finished before every generated-resource task starts.
153+ ./gradlew clean
154+ ./gradlew assembleRelease
129155 )
130156 built_apk=" $project_dir /app/build/outputs/apk/release/app-release.apk"
131157 if [[ ! -f " $built_apk " ]]; then
0 commit comments