Repository navigation
Expand file tree
/
Copy pathandro.bat
More file actions
439 lines (374 loc) · 13.1 KB
/
Copy pathandro.bat
File metadata and controls
439 lines (374 loc) · 13.1 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
@echo off
setlocal enabledelayedexpansion
REM Andro - Build Android APK and AAB from andro.yml configuration
REM Usage: andro [build|clean|init|help]
set "SCRIPT_DIR=%~dp0"
set "CURRENT_DIR=%CD%"
REM Handle 'init' command early (before config search) since it creates new config
if "%1"=="init" goto :init
if "%1"=="help" goto :help
REM For other commands, search for andro.yml in current directory and parent directories
set "CONFIG_DIR=%CURRENT_DIR%"
:find_config
set "CONFIG_FILE=%CONFIG_DIR%\andro.yml"
if exist "%CONFIG_FILE%" goto :config_found
set "PARENT_DIR=%CONFIG_DIR%\.."
if /i "%PARENT_DIR%"=="%CONFIG_DIR%" goto :config_not_found
set "CONFIG_DIR=%PARENT_DIR%"
goto :find_config
:config_not_found
echo ERROR: Configuration file (andro.yml) not found in current directory or any parent directory.
echo Current directory: %CURRENT_DIR%
echo.
echo Use "andro init" to create a new project configuration.
exit /b 1
:config_found
REM Set ANDROID_DIR relative to where andro.yml was found
set "ANDROID_DIR=%CONFIG_DIR%\android"
set "SCRIPT_ANDROID_DIR=%SCRIPT_DIR%android"
if "%1"=="" goto :build
if "%1"=="build" goto :build
if "%1"=="clean" goto :clean
echo Unknown command: %1
echo Use "andro help" for usage information
exit /b 1
:help
echo Andro - Android Build Tool
echo.
echo Usage: andro [command]
echo.
echo Commands:
echo build Build APK and AAB from andro.yml (default)
echo clean Clean build artifacts
echo init Initialize a new project (create andro.yml)
echo help Show this help message
echo.
echo Configuration file: andro.yml
goto :eof
:init
echo ============================================
echo Andro Init - Create New Project
echo ============================================
echo.
echo Script directory: %SCRIPT_DIR%
echo Current directory: %CURRENT_DIR%
echo.
REM Check if andro.yml already exists
if exist "%CURRENT_DIR%\andro.yml" (
echo ERROR: andro.yml already exists in:
echo %CURRENT_DIR%\andro.yml
echo.
echo Delete it first or choose a different directory.
exit /b 1
)
REM Test write permission
echo Testing write permission...
echo test > "%CURRENT_DIR%\test_write.tmp" 2>nul
if errorlevel 1 (
echo.
echo ERROR: Cannot write to current directory!
echo Directory: %CURRENT_DIR%
echo.
echo Please run from a writable directory.
exit /b 1
)
del "%CURRENT_DIR%\test_write.tmp" >nul 2>&1
set errorlevel=0
echo Write permission: OK
echo.
REM Create andro.yml
echo Creating andro.yml...
(
echo - title: ""
echo - version: "1"
echo - package: "com.mzaini30."
echo - icon: ""
echo - web: "html"
echo - ads: ""
) > "%CURRENT_DIR%\andro.yml"
if exist "%CURRENT_DIR%\andro.yml" (
echo Created: %CURRENT_DIR%\andro.yml
)
echo.
REM Copy andro.md if exists
echo Checking for andro.md...
echo Source: %SCRIPT_DIR%\andro.md
if exist "%SCRIPT_DIR%\andro.md" (
echo Copying andro.md...
copy /Y "%SCRIPT_DIR%\andro.md" "%CURRENT_DIR%\andro.md"
if exist "%CURRENT_DIR%\andro.md" (
echo Copied: %CURRENT_DIR%\andro.md
) else (
echo WARNING: Failed to copy andro.md
)
) else (
echo andro.md not found in %SCRIPT_DIR% [skipping]
)
echo.
echo ============================================
echo Init Complete!
echo ============================================
echo.
echo Next steps:
echo 1. Edit andro.yml to configure your app
echo 2. Copy the android\ folder to this directory
echo 3. Run "andro build" to build your APK
echo.
goto :eof
:clean
echo Cleaning build artifacts...
if exist "%CONFIG_DIR%\android\build" rmdir /s /q "%CONFIG_DIR%\android\build"
if exist "%CONFIG_DIR%\android\app\build" rmdir /s /q "%CONFIG_DIR%\android\app\build"
if exist "%CONFIG_DIR%\android\.gradle" rmdir /s /q "%CONFIG_DIR%\android\.gradle"
if exist "%CONFIG_DIR%\android\app" rmdir /s /q "%CONFIG_DIR%\android\app"
if exist "%CONFIG_DIR%\android\gradle" rmdir /s /q "%CONFIG_DIR%\android\gradle"
if exist "%CONFIG_DIR%\android\local.properties" del /q "%CONFIG_DIR%\android\local.properties"
echo Clean complete.
goto :eof
:build
echo ============================================
echo Andro - Android Build Tool
echo ============================================
echo.
REM Check and create .gitignore if not exists
if not exist "%CONFIG_DIR%\.gitignore" (
echo Creating .gitignore...
(
echo # Android build artifacts
echo android/build/
echo android/app/build/
echo android/.gradle/
echo android/app/src/main/res/mipmap-*/
echo android/app/src/main/res/drawable-*/
echo *.apk
echo *.aab
echo *.jks
echo *.keystore
echo.
echo # Gradle
echo .gradle/
echo gradle-app.secure.properties
echo.
echo # IDE
echo .idea/
echo *.iml
echo *.ipr
echo *.iws
echo ) > "%CONFIG_DIR%\.gitignore"
echo Created: %CONFIG_DIR%\.gitignore
echo.
)
REM Check if andro.yml exists
if not exist "%CONFIG_FILE%" (
echo ERROR: Configuration file not found: %CONFIG_FILE%
exit /b 1
)
echo Reading configuration from %CONFIG_FILE%...
echo.
REM Parse YAML configuration using PowerShell
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_ANDROID_DIR%\parse_yaml.ps1" -configFile "%CONFIG_FILE%" > "%TEMP%\andro_config.tmp"
for /f "usebackq delims=" %%i in ("%TEMP%\andro_config.tmp") do set "%%i"
del "%TEMP%\andro_config.tmp"
echo Configuration loaded:
echo Title: %APP_TITLE%
echo Version: %APP_VERSION%
echo Package: %APP_PACKAGE%
echo Icon: %APP_ICON%
echo Web: %APP_WEB%
echo Start.io ID: %APP_ADS%
echo.
REM Check Java
where java >nul 2>nul
if errorlevel 1 (
echo ERROR: Java not found in PATH.
echo Please install JDK 11 or higher.
exit /b 1
)
java -version >nul 2>&1
for /f "tokens=3" %%v in ('java -version 2^>^&1 ^| findstr /i "version"') do set "JAVA_VERSION=%%v"
echo Java version: %JAVA_VERSION%
echo.
REM Bootstrap Gradle if needed
if not exist "%ANDROID_DIR%\gradle\wrapper\gradle-wrapper.jar" (
echo Setting up Gradle wrapper...
REM Create gradle wrapper directory in output folder
if not exist "%ANDROID_DIR%\gradle\wrapper" mkdir "%ANDROID_DIR%\gradle\wrapper"
REM Copy gradlew.bat to output directory
copy /Y "%SCRIPT_ANDROID_DIR%\gradlew.bat" "%ANDROID_DIR%\gradlew.bat" >nul
REM Copy gradle-wrapper.properties to output directory
copy /Y "%SCRIPT_ANDROID_DIR%\gradle\wrapper\gradle-wrapper.properties" "%ANDROID_DIR%\gradle\wrapper\gradle-wrapper.properties" >nul
REM Download gradle-wrapper.jar directly to output directory
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/gradle/gradle/v8.0.0/gradle/wrapper/gradle-wrapper.jar' -OutFile '%ANDROID_DIR%\gradle\wrapper\gradle-wrapper.jar' -UseBasicParsing"
echo Gradle wrapper setup complete.
echo.
)
REM Accept SDK licenses automatically
call :accept_sdk_licenses
REM Generate project structure
echo Generating Android project structure...
REM Create directories using PowerShell (pass scriptDir without trailing backslash)
set "SCRIPT_DIR_PARAM=%ANDROID_DIR%"
if "%SCRIPT_DIR_PARAM:~-1%"=="\" set "SCRIPT_DIR_PARAM=%SCRIPT_DIR_PARAM:~0,-1%"
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_ANDROID_DIR%\create_dirs.ps1" -scriptDir "%SCRIPT_DIR_PARAM%" -appPackage "%APP_PACKAGE%"
if errorlevel 1 (
echo ERROR: Failed to create directory structure.
exit /b 1
)
REM Copy icon (resolve path relative to config directory)
set "ICON_SRC=%CONFIG_DIR%\%APP_ICON%"
if exist "%ICON_SRC%" (
echo Resizing icon: %APP_ICON%
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%SCRIPT_ANDROID_DIR%\resize_icon.ps1' -inputPath '%ICON_SRC%' -outputPath '%ANDROID_DIR%\app\src\main\res\drawable\ic_launcher.png' -maxSize 512"
if errorlevel 1 (
echo WARNING: Icon processing failed.
) else (
echo Icon processed: %APP_ICON%
)
) else (
echo WARNING: Icon file not found: %ICON_SRC%
)
REM Copy web assets (resolve path relative to config directory)
set "WEB_SRC=%CONFIG_DIR%\%APP_WEB%"
if exist "%WEB_SRC%" (
echo Copying web assets from %APP_WEB%...
REM Ensure assets directory exists
if not exist "%ANDROID_DIR%\app\src\main\assets" mkdir "%ANDROID_DIR%\app\src\main\assets"
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%SCRIPT_ANDROID_DIR%\copy_assets.ps1' -sourcePath '%WEB_SRC%' -destPath '%ANDROID_DIR%\app\src\main\assets'"
if errorlevel 1 (
echo ERROR: Failed to copy web assets.
exit /b 1
)
echo Web assets copied.
) else (
echo ERROR: Web folder not found: %WEB_SRC%
echo.
echo Please ensure the 'web' path in andro.yml points to a valid folder.
echo Current web path: %APP_WEB%
echo Expected location: %WEB_SRC%
exit /b 1
)
REM Generate keystore if not exists (in android directory)
if not exist "%ANDROID_DIR%\keystore.jks" (
echo Generating keystore...
call :generate_keystore
) else (
echo Keystore found.
)
REM Generate source files using PowerShell
echo Generating source files...
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%SCRIPT_ANDROID_DIR%\generate_project.ps1' -title '%APP_TITLE%' -version '%APP_VERSION%' -package '%APP_PACKAGE%' -icon '%APP_ICON%' -web '%APP_WEB%' -ads '%APP_ADS%' -output '%ANDROID_DIR%'"
if errorlevel 1 (
echo ERROR: Failed to generate source files.
exit /b 1
)
REM Update local.properties with actual SDK path (use forward slashes to avoid escaping issues)
if exist "D:\Android\Sdk" (
echo sdk.dir=D:/Android/Sdk> "%ANDROID_DIR%\local.properties"
)
REM Copy andro.md to output directory if it exists
if exist "%SCRIPT_ANDROID_DIR%\..\andro.md" (
copy /Y "%SCRIPT_ANDROID_DIR%\..\andro.md" "%CONFIG_DIR%\andro.md" >nul
echo andro.md copied to %CONFIG_DIR%.
)
REM Build with Gradle
echo.
echo ============================================
echo Building APK and AAB...
echo ============================================
echo.
cd /d "%ANDROID_DIR%"
REM Run Gradle build
if exist "%ANDROID_DIR%\gradlew.bat" (
call "%ANDROID_DIR%\gradlew.bat" assembleRelease assembleDebug bundleRelease --no-daemon
) else (
gradle assembleRelease assembleDebug bundleRelease --no-daemon
)
if errorlevel 1 (
echo.
echo ============================================
echo Build Failed!
echo ============================================
echo.
echo Common issues:
echo - Java JDK 11+ not installed or not in PATH
echo - ANDROID_HOME environment variable not set
echo - Android SDK not installed
echo - Internet connection required for Gradle downloads
echo.
exit /b 1
)
echo.
echo ============================================
echo Build Complete!
echo ============================================
echo.
REM Rename APK and AAB files using the app title
echo Renaming output files...
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_ANDROID_DIR%\rename_output.ps1" -title "%APP_TITLE%" -androidDir "%ANDROID_DIR%"
echo.
cd /d "%CONFIG_DIR%"
goto :eof
:generate_keystore
keytool -genkey -v ^
-keystore "%ANDROID_DIR%\keystore.jks" ^
-keyalg RSA ^
-keysize 2048 ^
-validity 10000 ^
-alias andro ^
-dname "CN=Muhammad Zaini, L=Samarinda, EMAIL=muhzaini30@gmail.com" ^
-storepass 0809894kali ^
-keypass 0809894kali
if errorlevel 1 (
echo ERROR: Failed to generate keystore.
exit /b 1
)
echo Keystore generated successfully.
goto :eof
:accept_sdk_licenses
echo.
echo Checking Android SDK licenses...
echo.
REM Try to get SDK path from local.properties first
set "SDK_DIR="
if exist "%ANDROID_DIR%\local.properties" (
for /f "tokens=2 delims==" %%a in ('findstr /c:"sdk.dir=" "%ANDROID_DIR%\local.properties"') do set "SDK_DIR=%%a"
)
REM Trim trailing whitespace and normalize path separators
if defined SDK_DIR (
call :trim_string "SDK_DIR"
set "SDK_DIR=%SDK_DIR:/=\%"
)
REM Fall back to ANDROID_HOME
if "%SDK_DIR%"=="" set "SDK_DIR=%ANDROID_HOME%"
REM Fall back to default location
if "%SDK_DIR%"=="" if exist "D:\Android\Sdk" set "SDK_DIR=D:\Android\Sdk"
if "%SDK_DIR%"=="" (
echo WARNING: Android SDK not found. Skipping license acceptance.
goto :eof
)
if not exist "%SDK_DIR%" (
echo WARNING: SDK directory not found: %SDK_DIR%
goto :eof
)
REM Create licenses directory
set "LICENSES_DIR=%SDK_DIR%\licenses"
if not exist "%LICENSES_DIR%" mkdir "%LICENSES_DIR%"
REM Create license files directly
echo Creating license files...
echo 24333f8a63b6825ea9c5514f83c2829b004d1fee > "%LICENSES_DIR%\android-sdk-license"
echo 8933bad161af4178b1185d1a37fbf41ea5269c55 >> "%LICENSES_DIR%\android-sdk-license"
echo d56f5187479451eabf01fb78af6dfcb131a6481e >> "%LICENSES_DIR%\android-sdk-license"
echo 24333f8a63b6825ea9c5514f83c2829b004d1fee >> "%LICENSES_DIR%\android-sdk-license"
echo Licenses accepted.
goto :eof
:trim_string
REM Helper function to trim leading/trailing whitespace from a variable
<
36DD
div>
setlocal enabledelayedexpansion
set "varName=%~1"
set "varValue=!%varName%!"
:trim_lead
if "!varValue:~0,1!"==" " set "varValue=!varValue:~1!" & goto trim_lead
:trim_trail
if "!varValue:~-1!"==" " set "varValue=!varValue:~0,-1!" & goto trim_trail
endlocal & set "%varName%=%varValue%"
goto :eof