feat(android): 添加rebuild选项强制重新编译Go代码

问题:
- build-apk.bat 只在 tsslib.aar 不存在时才编译Go代码
- clean 选项只清理Gradle构建文件,不删除tsslib.aar
- 导致Go代码修改后无法被编译进APK

解决方案:
- 添加 rebuild 选项到 build-apk.bat 和 build-install-debug.bat
- rebuild 会删除 tsslib.aar 并强制重新编译Go代码

使用方法:
- build-apk.bat rebuild          # 重新编译Go并构建APK
- build-install-debug.bat rebuild # 重新编译Go并安装调试APK

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-27 09:19:22 -08:00
parent 8a9a983cbd
commit b4541129aa
2 changed files with 74 additions and 2 deletions

View File

@ -183,8 +183,22 @@ set BUILD_TYPE=all
if "%1"=="debug" set BUILD_TYPE=debug
if "%1"=="release" set BUILD_TYPE=release
if "%1"=="clean" set BUILD_TYPE=clean
if "%1"=="rebuild" set BUILD_TYPE=rebuild
if "%1"=="help" goto :show_help
:: Handle rebuild - delete tsslib.aar to force recompilation of Go code
if "%BUILD_TYPE%"=="rebuild" (
echo [INFO] Rebuild requested - deleting tsslib.aar to recompile Go code...
if exist "app\libs\tsslib.aar" (
del /f "app\libs\tsslib.aar"
echo [INFO] tsslib.aar deleted, will be rebuilt
) else (
echo [INFO] tsslib.aar not found, will be built fresh
)
set BUILD_TYPE=all
echo.
)
:: Show build type
echo Build type: %BUILD_TYPE%
echo.
@ -275,14 +289,16 @@ echo Options:
echo debug - Build debug APK only
echo release - Build release APK only
echo all - Build both debug and release APKs (default)
echo clean - Clean build files
echo clean - Clean Gradle build files
echo rebuild - Delete tsslib.aar and rebuild everything (use after Go code changes)
echo help - Show this help message
echo.
echo Examples:
echo build-apk.bat - Build both APKs
echo build-apk.bat debug - Build debug APK only
echo build-apk.bat release - Build release APK only
echo build-apk.bat clean - Clean project
echo build-apk.bat clean - Clean Gradle project
echo build-apk.bat rebuild - Recompile Go code and build APKs
echo.
:end

View File

@ -7,6 +7,62 @@ echo Build - Install - Launch - Debug
echo ========================================
echo.
:: Check for rebuild flag
if "%1"=="rebuild" (
echo [0/5] Rebuild requested - deleting tsslib.aar to recompile Go code...
if exist "app\libs\tsslib.aar" (
del /f "app\libs\tsslib.aar"
echo [INFO] tsslib.aar deleted, will be rebuilt
) else (
echo [INFO] tsslib.aar not found, will be built fresh
)
echo.
:: Build tsslib.aar
echo [0/5] Building tsslib.aar...
:: Get GOPATH for bin directory
for /f "tokens=*" %%G in ('go env GOPATH') do set "GOPATH_DIR=%%G"
if not defined GOPATH_DIR set "GOPATH_DIR=%USERPROFILE%\go"
set "GOBIN_DIR=!GOPATH_DIR!\bin"
:: Add GOPATH/bin to PATH if not already there
echo !PATH! | findstr /i /c:"!GOBIN_DIR!" >nul 2>nul
if !errorlevel! neq 0 (
set "PATH=!PATH!;!GOBIN_DIR!"
)
pushd tsslib
"!GOBIN_DIR!\gomobile.exe" bind -target=android -androidapi 21 -o "..\app\libs\tsslib.aar" .
if !errorlevel! neq 0 (
echo [ERROR] gomobile bind failed!
popd
pause
exit /b 1
)
popd
echo [SUCCESS] tsslib.aar rebuilt!
for %%F in ("app\libs\tsslib.aar") do echo Size: %%~zF bytes
echo.
)
:: Show help
if "%1"=="help" (
echo Usage: build-install-debug.bat [option]
echo.
echo Options:
echo rebuild - Delete and rebuild tsslib.aar before building APK
echo help - Show this help message
echo.
echo Examples:
echo build-install-debug.bat - Build and install debug APK
echo build-install-debug.bat rebuild - Rebuild Go code, then build and install
echo.
pause
exit /b 0
)
:: Step 1: Build Debug APK
echo [1/5] Building Debug APK...
call gradlew.bat assembleDebug --no-daemon