dx dex java1.8,如何强制Delphi使用D8.bat而不是dx.bat将Java 1.8字节码编译为DEX字节码...

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值