segfault-bilibili 2e4f815732
Automatic build with GitHub Actions (#5)
* extract armv7 lib; make build.bat immune to spaced path

* update submodules

1.update dobby to latest:
original commit hash: b0176de574104726bb68dff3b77ee666300fc338
plus compilation error fix

2.update untp to include plistlib fix

* fix build errors

1. define RS_SUCCESS in MagiaClient.cpp,
which was deleted in Dobby f4643b8d14d7cc94516b446ca77d952d0b986d50

2. fix dobby not being statically linked

* terminate build script on error

let exit on error
let build.bat fail if signing fails

* sign_example.bat: use zipalign and apksigner

* upgrade to apktool 2.7.0; check hash of apktool

* handle fake python3

* control whether to include audiofix

* build.bat: go back to base dir on exit

* update readme

* update suggested ndk path

* build and release with GitHub Actions

* avoid unnecessary rebuild

* remove nodejs dependency

fix Dobby so that we can implement audiofix in MagiaHook again

* automatic build

* update apktool to 2.8.1

* fix max method number exceeded
2023-08-10 20:11:14 +01:00

192 lines
7.5 KiB

@echo off
if "%1" == "Debug" (
set BUILD_TYPE="Debug"
) else if "%1" == "Release" (
set BUILD_TYPE="Release"
) else (
echo Build type must be either Release or Debug
goto errorexit
for /r "%~dp0\apk" %%a in (*.apk) do set apk=%%~dpnxa
if "%apk%" neq "" (
echo Found apk %apk%.
goto :find_armv7_apk
echo Did not find any MagiReco APK! Add it to the apk/ directory.
goto errorexit
for /r "%~dp0\armv7apk" %%a in (*.apk) do set armv7apk=%%~dpnxa
if "%armv7apk%" neq "" (
echo Found ARMv7 apk %armv7apk%.
goto :start
echo Did not find any ARMv7 MagiReco APK! Add it to the armv7apk directory.
goto errorexit
if "%JAVA_HOME%" == "" (
echo JAVA_HOME is not set
goto errorexit
set ndk="C:/Android/Sdk/ndk/23.1.7779620"
set /p ndk="Enter ndk Location [%ndk%]: "
set cmake="C:/Android/sdk/cmake/3.22.1/bin/cmake.exe"
set /p cmake="Enter cmake Location [%cmake%]: "
set ninja="C:/Android/sdk/cmake/3.22.1/bin/ninja.exe"
set /p ninja="Enter ninja Location [%ninja%]: "
set zipalign="C:/Android/sdk/build-tools/34.0.0/zipalign.exe"
set /p zipalign="Enter zipalign Location [%zipalign%]: "
set apksigner="C:/Android/sdk/build-tools/34.0.0/apksigner.bat"
set /p apksigner="Enter apksigner Location [%apksigner%]: "
if not exist "%~dp0\build" mkdir "%~dp0\build"
set apktooljar=apktool_2.7.0.jar
set apktoolsha256=c11b5eb518d9ac2ab18e959cbe087499079072b04d567cdcae5ceb447f9a7e7d
if exist "%~dp0\build\%apktooljar%" goto checkapktoolhash
echo Downloading apktool...
CALL curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36" -o "%~dp0\build\%apktooljar%" -L ""
certutil -hashfile "%~dp0\build\%apktooljar%" SHA256 | findstr /i %apktoolsha256% && goto apktoolexists
echo SHA256 mismatch for "%~dp0\build\%apktooljar%"set deleteold=N
set redownloadapktool=N
set /p redownloadapktool="Try delete and redownload apktool (uppercase Y/[N])? "
if %redownloadapktool% NEQ Y goto errorexit
del /f "%~dp0\build\%apktooljar%"
goto downloadapktool
if not exist "%~dp0\build\app\" goto create
set deleteold=N
set /p deleteold="Remake existing APK work directory (uppercase Y/[N])? "
if %deleteold% NEQ Y goto build
echo Removing existing build files...
rmdir /S /Q "%~dp0\build\app\"
rmdir /S /Q "%~dp0\build\armv7\app\"
echo Running apktool...
CALL "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\build\%apktooljar%" d "%apk%" -o "%~dp0\build\app"
mkdir "%~dp0\build\app\smali_classes2\com\loadLib\"
if not exist "%~dp0\build\app\lib\armeabi-v7a" mkdir "%~dp0\build\app\lib\armeabi-v7a"
if not exist "%~dp0\build\app\lib\arm64-v8a" mkdir "%~dp0\build\app\lib\arm64-v8a"
echo Extracting ARMv7 lib...
CALL "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\build\%apktooljar%" d "%armv7apk%" --no-src --no-res -o "%~dp0\build\armv7\app"
move "%~dp0\build\armv7\app\lib\armeabi-v7a\*.*" "%~dp0\build\app\lib\armeabi-v7a\"
if errorlevel 1 goto errorexit
rmdir /S /Q "%~dp0\build\armv7\app\"
set tried_set_gitattr=N
echo Applying smali patches...
cd /d "%~dp0"
for %%a in (
) do (
call git apply --stat "%~dp0\patches\%%a"
call git apply "%~dp0\patches\%%a"
if errorlevel 1 goto handle_eol
goto apply_misc_patch
echo handle_eol
if "%tried_set_gitattr%" == "Y" goto errorexit
set tried_set_gitattr=Y
echo Convert all smali files from CRLF into LF...
cd /d "%~dp0"
powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass ".\convert_smali_eol.ps1"
goto apply_patch
echo Applying misc patches...
REM call copy /Y "%~dp0\patches\images\story_ui_sprites00_patch.plist" "%~dp0\build\app\assets\package\story\story_ui_sprites00.plist"
REM call copy /Y "%~dp0\patches\images\story_ui_sprites00_patch.png" "%~dp0\build\app\assets\package\story\story_ui_sprites00.png"
call copy /Y "%~dp0\patches\koruri-semibold.ttf" "%~dp0\build\app\assets\fonts\koruri-semibold.ttf"
echo Updating sprites and AndroidManifest.xml...
REM handle fake python3 which does nothing but redirects to microsoft store
set python=python
python3 --version && set python=python3
cd /d "%~dp0"
REM %python% -m pip install -r requirements.txt
if errorlevel 1 goto errorexit
echo Copying new smali files...
call copy /Y "%~dp0\smali\loader\*.smali" "%~dp0\build\app\smali_classes2\com\loadLib\"
mkdir "%~dp0\build\app\smali_classes2\io\kamihama\magianative\"
echo Copying magianative...
call copy /Y "%~dp0\smali\MagiaNative\app\src\main\java\io\kamihama\magianative\*.smali" "%~dp0\build\app\smali_classes2\io\kamihama\magianative\"
echo Copying libraries...
REM robocopy does not eat quoted paths
pushd "%~dp0"
call robocopy /NFL /NDL /NJH /NJS /nc /ns /e smali\okhttp-smali\okhttp3\ build\app\smali_classes2\okhttp3\
call robocopy /NFL /NDL /NJH /NJS /nc /ns /e smali\okhttp-smali\okio\ build\app\smali_classes2\okio\
echo Copying unknown...
call robocopy /NFL /NDL /NJH /NJS /nc /ns /e patches\unknown\ build\app\unknown\
call copy /Y "%~dp0\patches\strings.xml" "%~dp0\build\app\res\values\strings.xml"
echo Building libraries.
rmdir /S /Q "%~dp0\build\armeabi-v7a\"
rmdir /S /Q "%~dp0\build\arm64-v8a\"
mkdir "%~dp0\build\armeabi-v7a"
mkdir "%~dp0\build\arm64-v8a"
echo Running cmake armeabi-v7a...
if "%MT_AUDIOFIX_3_0_1%" == "" set MT_AUDIOFIX_3_0_1=Y
if "%MT_AUDIOFIX_3_0_1%" == "y" set MT_AUDIOFIX_3_0_1=Y
if "%MT_AUDIOFIX_3_0_1%" == "Y" (
cd /d "%~dp0\build\armeabi-v7a"
if errorlevel 1 goto errorexit
call "%ninja%"
if errorlevel 1 goto errorexit
echo Running cmake arm64-v8a...
cd /d "%~dp0\build\arm64-v8a"
if errorlevel 1 goto errorexit
call "%ninja%"
if errorlevel 1 goto errorexit
echo Copying libraries...
call copy /Y "%~dp0\build\armeabi-v7a\" "%~dp0\build\app\lib\armeabi-v7a\"
call copy /Y "%~dp0\build\arm64-v8a\" "%~dp0\build\app\lib\arm64-v8a\"
echo Rebuilding APK...
CALL "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\build\%apktooljar%" b "%~dp0\build\app" -o "%~dp0\build\magia_patched.apk"
echo Signing apk...
call "%~dp0\sign.bat"
if errorlevel 1 goto errorexit
echo Finished!
goto exit
echo An error has occurred, exiting.
goto exit
cd /d "%~dp0"