build-aar-windows.bat
2.38 KB
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
@echo off
setlocal EnableExtensions
rem Windows one-click build for native-fast-printer AAR
rem It calls android-src/build-aar.sh via bash (Git Bash or bash in PATH).
rem
rem 注意:标签 :label 不能写在 if/for的圆括号块里面,否则双击运行会立刻退出(窗口闪一下)。
set "SCRIPT_DIR=%~dp0"
pushd "%SCRIPT_DIR%" || (
echo [ERROR] Cannot cd to script directory.
pause
exit /b 1
)
rem 1) locate bash
where bash >nul 2>nul
if errorlevel 1 (
if exist "C:\Program Files\Git\bin\bash.exe" (
set "BASH_EXE=C:\Program Files\Git\bin\bash.exe"
) else (
echo [ERROR] bash not found.
echo Please install Git for Windows ^(Git Bash^) or add bash to PATH.
popd
pause
exit /b 1
)
) else (
set "BASH_EXE=bash"
)
rem 2) choose ANDROID_JAR (try API 34 down to 21 under SDK root)
if "%ANDROID_JAR%"=="" call :pick_android_jar
if "%ANDROID_JAR%"=="" (
echo [ERROR] Android jar not found under SDK roots.
echo Install an Android platform in SDK Manager ^(API 34 or lower^),
echo or set ANDROID_JAR to an existing ...\platforms\android-XX\android.jar
popd
pause
exit /b 1
)
if not exist "%ANDROID_JAR%" (
echo [ERROR] Android jar path is invalid:
echo %ANDROID_JAR%
popd
pause
exit /b 1
)
echo Using ANDROID_JAR:
echo %ANDROID_JAR%
rem 3) build via bash (log便于排查)
set "LOG_FILE=%SCRIPT_DIR%build-aar.log"
echo Log: %LOG_FILE%
del /f /q "%LOG_FILE%" >nul 2>nul
echo Running: %BASH_EXE% build-aar.sh
if /I "%BASH_EXE%"=="bash" (
bash build-aar.sh > "%LOG_FILE%" 2>&1
) else (
"%BASH_EXE%" build-aar.sh > "%LOG_FILE%" 2>&1
)
set "RC=%ERRORLEVEL%"
if not "%RC%"=="0" (
echo [ERROR] build-aar.sh failed. exitCode=%RC%
echo See log:
echo %LOG_FILE%
) else (
echo [OK] Built AAR successfully.
echo See log:
echo %LOG_FILE%
)
popd
pause
exit /b %RC%
rem ---------- subroutines (must be after main exit) ----------
:pick_android_jar
set "ANDROID_JAR="
set "SDK_ROOT_CAND=%ANDROID_HOME%"
if "%SDK_ROOT_CAND%"=="" set "SDK_ROOT_CAND=%ANDROID_SDK_ROOT%"
if "%SDK_ROOT_CAND%"=="" set "SDK_ROOT_CAND=%LOCALAPPDATA%\Android\Sdk"
if "%SDK_ROOT_CAND%"=="" set "SDK_ROOT_CAND=%USERPROFILE%\AppData\Local\Android\Sdk"
for /L %%V in (34,-1,21) do (
if exist "%SDK_ROOT_CAND%\platforms\android-%%V\android.jar" (
set "ANDROID_JAR=%SDK_ROOT_CAND%\platforms\android-%%V\android.jar"
exit /b 0
)
)
exit /b 1