3ead62fc
杨鑫
优化
|
1
|
@echo off
|
699ea6e8
杨鑫
完善打印逻辑
|
2
|
setlocal EnableExtensions EnableDelayedExpansion
|
3ead62fc
杨鑫
优化
|
3
4
5
6
|
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
|
699ea6e8
杨鑫
完善打印逻辑
|
7
|
rem 目标:双击不闪退;失败时把原因与日志直接打印到窗口里。
|
3ead62fc
杨鑫
优化
|
8
|
|
699ea6e8
杨鑫
完善打印逻辑
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
rem Better Chinese output on most Windows terminals
chcp 65001 >nul 2>nul
title native-fast-printer AAR build
set "RC=0"
call :main
set "RC=!ERRORLEVEL!"
echo.
if not "!RC!"=="0" (
echo [FAILED] exitCode=!RC!
) else (
echo [OK] exitCode=0
)
echo.
echo Press any key to close...
pause >nul
exit /b !RC!
:main
|
3ead62fc
杨鑫
优化
|
29
|
set "SCRIPT_DIR=%~dp0"
|
699ea6e8
杨鑫
完善打印逻辑
|
30
31
32
|
echo [INFO] scriptDir=!SCRIPT_DIR!
pushd "!SCRIPT_DIR!"
if errorlevel 1 (
|
3ead62fc
杨鑫
优化
|
33
|
echo [ERROR] Cannot cd to script directory.
|
3ead62fc
杨鑫
优化
|
34
35
36
|
exit /b 1
)
|
699ea6e8
杨鑫
完善打印逻辑
|
37
38
|
echo [INFO] cwd=!CD!
|
3ead62fc
杨鑫
优化
|
39
|
rem 1) locate bash
|
699ea6e8
杨鑫
完善打印逻辑
|
40
41
42
43
|
set "BASH_EXE="
if exist "C:\Program Files\Git\bin\bash.exe" (
set "BASH_EXE=C:\Program Files\Git\bin\bash.exe"
goto bash_ok
|
3ead62fc
杨鑫
优化
|
44
|
)
|
699ea6e8
杨鑫
完善打印逻辑
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
bash --version >nul 2>nul
if errorlevel 1 goto bash_missing
set "BASH_EXE=bash"
:bash_ok
echo [INFO] bash=!BASH_EXE!
goto bash_done
:bash_missing
echo [ERROR] bash not found.
echo Please install Git for Windows (Git Bash) or add bash to PATH.
echo Expected: "C:\Program Files\Git\bin\bash.exe"
popd
exit /b 1
:bash_done
|
3ead62fc
杨鑫
优化
|
60
61
|
rem 2) choose ANDROID_JAR (try API 34 down to 21 under SDK root)
|
699ea6e8
杨鑫
完善打印逻辑
|
62
63
64
65
|
if not defined ANDROID_JAR call :pick_android_jar
echo [INFO] ANDROID_JAR(final)=!ANDROID_JAR!
if not defined ANDROID_JAR goto android_jar_missing
goto android_jar_ok
|
3ead62fc
杨鑫
优化
|
66
|
|
699ea6e8
杨鑫
完善打印逻辑
|
67
68
69
70
71
72
73
74
75
76
77
|
:android_jar_missing
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
echo Checked roots:
echo ANDROID_HOME=!ANDROID_HOME!
echo ANDROID_SDK_ROOT=!ANDROID_SDK_ROOT!
echo LOCALAPPDATA=!LOCALAPPDATA!\Android\Sdk
echo USERPROFILE=!USERPROFILE!\AppData\Local\Android\Sdk
popd
exit /b 1
|
3ead62fc
杨鑫
优化
|
78
|
|
699ea6e8
杨鑫
完善打印逻辑
|
79
80
|
:android_jar_ok
if not exist "!ANDROID_JAR!" (
|
3ead62fc
杨鑫
优化
|
81
|
echo [ERROR] Android jar path is invalid:
|
699ea6e8
杨鑫
完善打印逻辑
|
82
|
echo !ANDROID_JAR!
|
3ead62fc
杨鑫
优化
|
83
|
popd
|
3ead62fc
杨鑫
优化
|
84
85
|
exit /b 1
)
|
699ea6e8
杨鑫
完善打印逻辑
|
86
|
echo [INFO] ANDROID_JAR=!ANDROID_JAR!
|
3ead62fc
杨鑫
优化
|
87
88
|
rem 3) build via bash (log便于排查)
|
699ea6e8
杨鑫
完善打印逻辑
|
89
90
91
|
set "LOG_FILE=!SCRIPT_DIR!build-aar.log"
echo [INFO] Log file: !LOG_FILE!
del /f /q "!LOG_FILE!" >nul 2>nul
|
3ead62fc
杨鑫
优化
|
92
|
|
699ea6e8
杨鑫
完善打印逻辑
|
93
|
echo [INFO] Running build-aar.sh ...
|
3ead62fc
杨鑫
优化
|
94
|
if /I "%BASH_EXE%"=="bash" (
|
699ea6e8
杨鑫
完善打印逻辑
|
95
|
bash build-aar.sh > "!LOG_FILE!" 2>&1
|
3ead62fc
杨鑫
优化
|
96
|
) else (
|
699ea6e8
杨鑫
完善打印逻辑
|
97
|
"!BASH_EXE!" build-aar.sh > "!LOG_FILE!" 2>&1
|
3ead62fc
杨鑫
优化
|
98
99
|
)
|
699ea6e8
杨鑫
完善打印逻辑
|
100
101
102
103
104
105
106
107
108
109
110
111
|
set "RC=!ERRORLEVEL!"
if not "!RC!"=="0" (
echo [ERROR] build-aar.sh failed. exitCode=!RC!
echo ---------------- build-aar.log tail ----------------
if exist "!LOG_FILE!" (
type "!LOG_FILE!"
) else (
echo (log file missing)
)
echo ------------------------------------------------------
popd
exit /b !RC!
|
3ead62fc
杨鑫
优化
|
112
113
|
) else (
echo [OK] Built AAR successfully.
|
699ea6e8
杨鑫
完善打印逻辑
|
114
115
116
117
118
|
echo ---------------- build-aar.log ----------------
if exist "!LOG_FILE!" type "!LOG_FILE!"
echo ------------------------------------------------
popd
exit /b 0
|
3ead62fc
杨鑫
优化
|
119
120
|
)
|
3ead62fc
杨鑫
优化
|
121
122
123
124
|
rem ---------- subroutines (must be after main exit) ----------
:pick_android_jar
set "ANDROID_JAR="
|
699ea6e8
杨鑫
完善打印逻辑
|
125
126
127
128
129
130
131
132
133
134
135
|
rem try multiple sdk roots in order
for %%R in ("!ANDROID_HOME!" "!ANDROID_SDK_ROOT!" "!LOCALAPPDATA!\Android\Sdk" "!USERPROFILE!\AppData\Local\Android\Sdk") do (
call :try_sdk_root "%%~R"
if not "!ANDROID_JAR!"=="" exit /b 0
)
exit /b 1
:try_sdk_root
set "SDK_ROOT=%~1"
if "!SDK_ROOT!"=="" exit /b 0
echo [INFO] scanning sdkRoot=!SDK_ROOT!
|
3ead62fc
杨鑫
优化
|
136
|
for /L %%V in (34,-1,21) do (
|
699ea6e8
杨鑫
完善打印逻辑
|
137
138
139
|
if exist "!SDK_ROOT!\platforms\android-%%V\android.jar" (
set "ANDROID_JAR=!SDK_ROOT!\platforms\android-%%V\android.jar"
echo [INFO] found android.jar: !ANDROID_JAR!
|
3ead62fc
杨鑫
优化
|
140
141
142
|
exit /b 0
)
)
|
699ea6e8
杨鑫
完善打印逻辑
|
143
|
exit /b 0
|