如何强制Delphi使用D8.bat而不是dx.bat将Java 1.8字节码编译为DEX字节码 [英] How to force Delphi to use D8.bat instead of dx.bat to compile Java 1.8 bytecode into DEX bytecode

查看:453
本文介绍了如何强制Delphi使用D8.bat而不是dx.bat将Java 1.8字节码编译为DEX字节码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我遇到了一个问题.我的项目需要使用一些使用Java 1.8功能的库(* .jar).我看到越来越多的库现在使用Java 1.8功能(例如webRTC,exoplayer等).通过这种方式,我们必须退货.

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.

通过解糖功能,您可以在构建过程中用较旧的字节码和语言API替换新的字节码和语言API,从而在较旧的设备上使用这些功能

Desugaring allows you to use these features on older devices by replacing new bytecodes and language APIs with older ones during the build process

使用d8.bat(代替dx.bat),默认情况下将启用反糖化.因此,您现在可以在定位较旧的设备时使用大多数最新的语言更改.

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.

当我们编译项目时,Delphi在后台执行此操作:

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"

dx.bat --dex --output="C:\Dev\output\libwebrtc-dexed.jar" "C:\Dev\lib\libwebrtc.jar"

并且对于包含Java 1.8功能的库,此操作将失败.

And this fails with a library that contains Java 1.8 features.

因此,Delphi必须改为执行此操作:

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"

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"

有什么主意我可以告诉Delphi使用d8.bat代替dx.bat吗?

Any idea how I can tell Delphi to use d8.bat instead of dx.bat?

推荐答案

我找到了一个解决方案,修改了"CodeGear.Common.Targets"文件(Delphi的bin文件夹),创建了一个替代命令,仅使用d8.bat而不是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)关闭IDE

2)编辑"CodeGear.Common.Targets",本地化DxCmd定义,并添加这两行,为d8.bat创建新命令:

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)现在,将用于生成dex文件的目标本地化,并用新的 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)现在,dex生成将使用d8.bat编译器,默认情况下"desugaring"处于启用状态.

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

这篇关于如何强制Delphi使用D8.bat而不是dx.bat将Java 1.8字节码编译为DEX字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆