Rebuilding the Delphi & C++Builder Android Java files

  

Some while back I posted a command script (or batch file as we used to call them) that could be used by RAD Studio 10.3 users if they felt the need to change any of the few Java files underlying Delphi’s (and C++Builder’s) Android RTL and FireMonkey code.The script would rebuild all the Java files into the required fmx.dex.jar and fmx.jar archives and copy them into the relevant RAD Studio installation folders to be used on subsequent builds.When I tried to use the script with RAD Studio 10.3.3 of course it didn’t work as things have changed, different files need to be involved in the process. I have updated the script now to work with RAD Studio 10.3.3 and thought I’d share it in case anyone else needs to do this.An obvious question is: Why would anyone else want to rebuild the Java Android RTL files? Well this is normally a necessary step if you find an issue in the code as Embarcadero ships it and you want to try to fix it or enhance it. Indeed the previous post on rebuilding the 10.3 Java files was all about patching the Java code to get Android Intent support working.If you have no interest in tweaking the Java code or fixing any issues you encounter in the Java code then you probably won’t be needing this script.If you do need the script, remember to take a backup of your original compiled archives before you proceed. These are found in:C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.jarC:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.dex.jarC:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.jarC:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.dex.jarThe script needs to be run from an administrative command prompt and before you run it you should double-check the various paths set up in the environment variables at the start are all valid on your system.The script can be found below (apologies for any layout issues caused by longer lines than the narrow blog width); hat-tip and thanks to Tom Byrnes for test-driving it:@echo offclsrem Android RTL Java files rebuilder for RAD Studio 10.3.3setlocal enabledelayedexpansionrem Set environment variablesrem *NOTE*: check these folders match your setupset EMBT=Embarcadero\Studio\20.0set BDS=%ProgramFiles(x86)%\%EMBT%set JAVA_PATH=%ProgramFiles%\Java\jdk1.8.0_60\binrem This is the default path for the Android SDK when installed from the .iso installerset SDK_PATH=%PUBLIC%\Documents\%EMBT%\PlatformSDKs\android-sdk-windowsif not exist “%SDK_PATH%\” ( rem This is the default path for the Android SDK when installed from the web install (aka ESD install) set SDK_PATH=%PUBLIC%\Documents\%EMBT%\CatalogRepository\AndroidSDK-2525_20.0.36039.7899)rem Set more environment variables based on those aboveset DX_PATH=%SDK_PATH%\build-tools\28.0.2set ANDROID_JAR=%SDK_PATH%\platforms\android-26\android.jarset BDS_LIB=%BDS%\libset BDS_DEBUG_LIB=%BDS%\lib\android\debugset BDS_RELEASE_LIB=%BDS%\lib\android\releaseset FMX_SRC_PATH=%BDS%\source\rtl\androiddex\java\fmxset CLASS_PATH=%ANDROID_JAR%set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\android-support-v4.jarset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\cloud-messaging.jarset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-base.16.0.1.jarset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-maps.16.1.0.jarset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\debug\com-google-android-gms.play-services-ads.17.2.0.jarrem For adListenerset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-ads-lite.17.2.0.jarrem For AbstractSafeParcelableset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-basement.16.2.0.jarrem For ReflectedParcelableset CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\com-google-android-gms.play-services-basement.16.2.0.jarecho.echo Checking environment variablesif not exist “%BDS%\” ( echo Path used to set BDS environment variable does not exist^^! Is RAD Studio installed elsewhere? goto :Error)if not exist “%JAVA_PATH%\” ( echo Path used to set JAVA_PATH environment variable does not exist^^! Is the JDK installed elsewhere? goto :Error)if not exist “%SDK_PATH%\” ( echo Path used to set SDK_PATH environment variable does not exist^^! Is the Android SDK installed elsewhere? goto :Error)if not exist “%ANDROID_JAR%” ( echo Path used to set ANDROID_JAR environment variable does not exist^^! Is your android.jar in a different platform folder? goto :Error)echo.echo Changing to the FMX source folderecho.pushd %FMX_SRC_PATH%echo Getting fully qualified list of all Java source file we need to rebuildecho.if not exist bin\classes mkdir bin\classesif not exist bin\debug mkdir bin\debugif not exist bin\release mkdir bin\releasedir src\android\bluetooth\*.java /s /b > JavaSources.txtdir src\android\telephony\*.java /s /b >> JavaSources.txtdir src\com\*.java /s /b >> JavaSources.txtecho Ensuring FMX source path ends in a ‘\’echo.set LAST_CHAR=%FMX_SRC_PATH:~-1%if not “%LAST_CHAR%”==”\” set FMX_SRC_PATH=%FMX_SRC_PATH%\echo Making Java source file paths relative to current directoryecho.if exist JavaSources2.txt del JavaSources2.txtfor /F “tokens=*” %%A in (JavaSources.txt) do ( set STR=%%A set “STR=!STR:%FMX_SRC_PATH%=!” echo !STR!>>JavaSources2.txt)echo Compiling all the FMX Java code into class files with debug infoecho.”%JAVA_PATH%”\javac -g -d bin\classes -classpath “%CLASS_PATH%” -encoding UTF-8 -g @JavaSources2.txtif errorlevel 1 ( echo. echo Problem encountered during Java compilation goto :Error)echo.echo Creating jar containing the new compiled FMX Java classes with debug infoecho.”%JAVA_PATH%”\jar cf bin\debug\fmx.jar -C bin\classes .if errorlevel 1 ( echo. echo Problem encountered during Java archiving goto :Error)echo Creating DEX jar containing the new compiled FMX Java classes with debug infoecho.call %DX_PATH%\dx –dex –output=bin\debug\fmx.dex.jar –positions=lines bin\debug\fmx.jarif errorlevel 1 ( echo. echo Problem encountered during DEXing goto :Error)echo Compiling all the FMX Java code into class files without debug infoecho.”%JAVA_PATH%”\javac -g:none -d bin\classes -classpath “%CLASS_PATH%” -encoding UTF-8 @JavaSources2.txtif errorlevel 1 ( echo. echo Problem encountered during Java compilation goto :Error)echo.echo Creating jar containing the new compiled FMX Java classes without debug infoecho.”%JAVA_PATH%”\jar cf bin\release\fmx.jar -C bin\classes .if errorlevel 1 ( echo. echo Problem encountered during Java archiving goto :Error)echo Creating DEX jar containing the new compiled FMX Java classes without debug infoecho.call %DX_PATH%\dx –dex –output=bin\release\fmx.dex.jar –positions=lines bin\release\fmx.jarif errorlevel 1 ( echo. echo Problem encountered during DEXing goto :Error)copy bin\debug\* “%BDS_DEBUG_LIB%”copy bin\release\* “%BDS_RELEASE_LIB%”echo Tidying up…echo.if exist JavaSources.txt del JavaSources.txtif exist JavaSources2.txt del JavaSources2.txtrd /s /q bingoto :End:Errorecho.echo Sorry, we had a problem :(echo.:Endecho Changing back to the folder we started inpopdendlocal

Comments are closed.