How to force Delphi to use D8.bat instead of dx.bat to compile Java 1.8 bytecode into DEX bytecode

北城余情 提交于 2019-12-08 07:20:51

问题


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?


回答1:


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:

<JavaD8Path>@(JavaAaptPath->'%(RootDir)%(Directory)')d8.bat</JavaD8Path>
<D8Cmd>PATH $(JDKPath)\bin;$(PATH) %26 "$(JavaD8Path)" --output=</D8Cmd>

3) Now localize the target used to generate the dex files and replace the DxCmd by the new D8Cmd

  <!-- Generate a "dexed" version of the customized jar files if they doesn´t exists -->
  <Target Name="BuildPredexedJar" DependsOnTargets="GetProjectJars">
    <Exec Condition="( '@(_JarsLocations)'!='' And !Exists('%(_JarsLocations.PredexedJar)') )"
        Command='$(D8Cmd)"%(_JarsLocations.PredexedJar)" %22%(_JarsLocations.FullPath)%22'/>
  </Target>

4) Now the dex generation will use the d8.bat compiler, where "desugaring" is turned on by default.



来源:https://stackoverflow.com/questions/53096378/how-to-force-delphi-to-use-d8-bat-instead-of-dx-bat-to-compile-java-1-8-bytecode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!