-
Notifications
You must be signed in to change notification settings - Fork 11
/
App_build_and_release.cmd
143 lines (141 loc) · 6.23 KB
/
App_build_and_release.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@echo off
setlocal enabledelayedexpansion
SET SCRIPT_PATH=%~dps0
cd /d "%SCRIPT_PATH%"
cls
REM
REM Script Consts.
SET CLEANUP_BEFORE_BUILD=1
REM
REM Runtime Variables.
IF EXIST "%LocalAppData%\Android\Sdk" SET "ANDROID_SDK_ROOT=%LocalAppData%\Android\Sdk"
IF NOT DEFINED ANDROID_SDK_ROOT SET "ANDROID_SDK_ROOT=%SCRIPT_PATH%..\syncthing-android-prereq"
REM
REM SET ANDROID_PUBLISHER_CREDENTIALS=%userprofile%\.android\play_key.json"
REM SET SYNCTHING_RELEASE_STORE_FILE="%userprofile%\.android\signing_key.jks"
SET SYNCTHING_RELEASE_KEY_ALIAS=Syncthing-Fork
SET BUILD_FLAVOUR_RELEASE=release
SET BUILD_FLAVOUR_GPLAY=gplay
title %SYNCTHING_RELEASE_KEY_ALIAS% - Build APK
REM
SET GIT_INSTALL_DIR=%ProgramFiles%\Git
SET GIT_BIN="%GIT_INSTALL_DIR%\bin\git.exe"
REM
SET JAVA_HOME=%ProgramFiles%\Android\Android Studio\jbr
SET PATH=%JAVA_HOME%\bin;"%GIT_INSTALL_DIR%\bin";%PATH%
REM
:checkPrerequisites
echo [INFO] Checking prerequisites ...
REM
where java 2>&1 >NUL: || (echo [ERROR] Java is missing. Check env. & goto :eof)
REM
IF NOT EXIST "%ANDROID_SDK_ROOT%\.knownPackages" (echo [WARN] Android SDK missing. Trying to run 'python install_minimum_android_sdk_prerequisites.py' ... & call python install_minimum_android_sdk_prerequisites.py)
REM
echo [INFO] Checking if SyncthingNative was built before starting this script ...
SET LIBCOUNT=
for /f "tokens=*" %%A IN ('dir /s /a "%SCRIPT_PATH%app\src\main\jniLibs\*" 2^>NUL: ^| find /C "libsyncthingnative.so"') DO SET LIBCOUNT=%%A
IF NOT "%LIBCOUNT%" == "4" echo [ERROR] SyncthingNative[s] "libsyncthingnative.so" are missing. Please run "gradlew buildNative" first. & goto :eos
REM
echo [INFO] Let's prepare a new "%SYNCTHING_RELEASE_KEY_ALIAS%" release.
REM
echo [INFO] Checking release prerequisites ...
IF NOT EXIST "%ANDROID_PUBLISHER_CREDENTIALS%" echo [ERROR] ANDROID_PUBLISHER_CREDENTIALS file not found. Please retry. & pause & goto :checkPrerequisites
FOR /F "tokens=*" %%i in ('type "%ANDROID_PUBLISHER_CREDENTIALS%" 2^>NUL:') DO SET ANDROID_PUBLISHER_CREDENTIALS=%%i
REM
REM User has to enter the signing password if it is not filled in here.
REM SET SIGNING_PASSWORD=
IF DEFINED SIGNING_PASSWORD goto :absLint
:enterSigningPassword
setlocal DisableDelayedExpansion
set "psCommand=powershell -Command "$pword = read-host 'Enter signing password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do SET SIGNING_PASSWORD=%%p
setlocal EnableDelayedExpansion
IF NOT DEFINED SIGNING_PASSWORD echo [ERROR] Signing password is required. Please retry. & goto :enterSigningPassword
REM
:absLint
REM
copy /y "%SCRIPT_PATH%app\src\main\play\release-notes\en-GB\beta.txt" "%SCRIPT_PATH%app\src\main\play\release-notes\en-GB\default.txt"
REM
echo [INFO] Running lint before building ...
REM
call gradlew lint%BUILD_FLAVOUR_RELEASE% & SET RESULT=%ERRORLEVEL%
REM IF NOT "!RESULT!" == "0" echo [ERROR] "gradlew lint%BUILD_FLAVOUR_RELEASE%" exited with code #%RESULT%. & goto :eos
REM
call gradlew lint%BUILD_FLAVOUR_GPLAY% & SET RESULT=%ERRORLEVEL%
IF NOT "!RESULT!" == "0" echo [ERROR] "gradlew lint%BUILD_FLAVOUR_GPLAY%" exited with code #%RESULT%. & goto :eos
REM
REM Building APK
REM
call :buildApk %BUILD_FLAVOUR_RELEASE%
call :buildApk %BUILD_FLAVOUR_GPLAY%
REM
IF "%CLEANUP_BEFORE_BUILD%" == "1" del /f "%SCRIPT_PATH%app\build\outputs\bundle\%BUILD_FLAVOUR_GPLAY%\app-%BUILD_FLAVOUR_GPLAY%.aab" 2> NUL:
echo [INFO] Building Android BUNDLE variant "%BUILD_FLAVOUR_GPLAY%" ...
call gradlew --quiet bundle%BUILD_FLAVOUR_GPLAY%
SET RESULT=%ERRORLEVEL%
IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew bundle%BUILD_FLAVOUR_GPLAY%" exited with code #%RESULT%. & goto :eos
REM
:absPostBuildScript
REM
echo [INFO] Running OPTIONAL post build script ...
call gradlew --quiet postBuildScript
REM
echo [INFO] Deleting unsupported play translations ...
call gradlew --quiet deleteUnsupportedPlayTranslations
SET RESULT=%ERRORLEVEL%
IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew deleteUnsupportedPlayTranslations" exited with code #%RESULT%. & goto :eos
REM
REM Copy build artifacts with correct file name to upload folder.
call "%SCRIPT_PATH%postbuild_copy_apk.cmd"
REM
:askUserReadyToPublish
SET UI_ANSWER=
SET /p UI_ANSWER=Are you ready to publish this release to GPlay? [y/n]
IF NOT "%UI_ANSWER%" == "y" goto :askUserReadyToPublish
REM
REM Workaround for play-publisher issue, see https://github.com/Triple-T/gradle-play-publisher/issues/597
:clearPlayPublisherCache
IF EXIST "app\build\generated\gpp" rd /s /q "app\build\generated\gpp"
IF EXIST "app\build\generated\gpp" TASKKILL /F /IM java.exe & sleep 1 & goto :clearPlayPublisherCache
REM
REM Publish text and image resources to GPlay
echo [INFO] Publishing descriptive resources to GPlay ...
call gradlew --quiet publish%BUILD_FLAVOUR_GPLAY%Listing
SET RESULT=%ERRORLEVEL%
IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew publish%BUILD_FLAVOUR_GPLAY%Listing" exited with code #%RESULT%. & pause & goto :clearPlayPublisherCache
REM
REM Publish APK to GPlay
echo [INFO] Publishing APK to GPlay ...
REM call gradlew --quiet publish%BUILD_FLAVOUR_GPLAY%
REM SET RESULT=%ERRORLEVEL%
REM IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew publish%BUILD_FLAVOUR_GPLAY%" exited with code #%RESULT%. & goto :eos
call gradlew --quiet publish%BUILD_FLAVOUR_GPLAY%Bundle
SET RESULT=%ERRORLEVEL%
IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew publishBundle" exited with code #%RESULT%. & pause & goto :clearPlayPublisherCache
REM
goto :eos
:eos
REM
echo [INFO] End of Script.
REM
pause
goto :eof
:buildApk
REM
REM Syntax:
REM call :buildApk [BUILD_TYPE]
REM
REM Variables.
SET "BA_BUILD_TYPE=%1"
IF NOT DEFINED BA_BUILD_TYPE echo [ERROR] buildApk: Parameter 1 BUILD_TYPE missing. & pause & goto :eof
REM
IF "%CLEANUP_BEFORE_BUILD%" == "1" del /f "%SCRIPT_PATH%app\build\outputs\apk\%BA_BUILD_TYPE%\app-%BA_BUILD_TYPE%.apk" 2> NUL:
echo [INFO] Building Android APK variant "%BA_BUILD_TYPE%" ...
call gradlew --quiet assemble%BA_BUILD_TYPE%
SET RESULT=%ERRORLEVEL%
IF NOT "%RESULT%" == "0" echo [ERROR] "gradlew assemble%BA_BUILD_TYPE%" exited with code #%RESULT%. & goto :eos
type "app\build\intermediates\merged_manifests\%BA_BUILD_TYPE%\process%BA_BUILD_TYPE%Manifest\AndroidManifest.xml" | findstr /i "android:version"
REM
goto :eof