Today I faced a problem. My project needs to use some libraries (*.jar) that use Java 1.8 features. I see more and more libraries use now Java 1.8 features (like webRTC, exoplayer, etc.). In this way, we must do desugaring.
Desugaring allows you to use these features on older devices by replacing new bytecodes and language APIs with older ones during the build process
With d8.bat (replacement of dx.bat), desugaring is turned on by default. So you can now use most of the latest language changes while targeting older devices.
When we compile a project, in the background Delphi does this:
dx.bat --dex --output="C:\Dev\output\libwebrtc-dexed.jar" "C:\Dev\lib\libwebrtc.jar"
And this fails with a library that contains Java 1.8 features.
So Delphi must do this instead:
d8.bat --lib C:\SDKs\android-sdk-windows\platforms\android-28\android.jar --output="C:\Dev\output\libwebrtc-dexed.jar" "C:\Dev\lib\libwebrtc.jar"
Any idea how I can tell Delphi to use d8.bat instead of dx.bat?
解决方案
I found a solution modifying the "CodeGear.Common.Targets" file (Delphi's bin folder), creating an alternative command to be used only for dex generation using the d8.bat instead of the dx.bat:
1) Close the IDE
2) Edit the "CodeGear.Common.Targets", localize the DxCmd definition, and add this two new lines, creating a new command for d8.bat:
@(JavaAaptPath->'%(RootDir)%(Directory)')d8.bat
PATH $(JDKPath)\bin;$(PATH) %26 "$(JavaD8Path)" --output=
3) Now localize the target used to generate the dex files and replace the DxCmd by the new D8Cmd
Command='$(D8Cmd)"%(_JarsLocations.PredexedJar)" %22%(_JarsLocations.FullPath)%22'/>
4) Now the dex generation will use the d8.bat compiler, where "desugaring" is turned on by default.