简体   繁体   English

用D8编译

[英]Compile with D8

I want to use the recently introduced D8 compiler from Google to build a dex file. 我想使用谷歌最近推出的D8编译器来构建一个dex文件。 Unfortunately, I didn't find the jar executable in the build-tools folder (like the dx tool). 不幸的是,我没有在build-tools文件夹中找到jar可执行文件(比如dx工具)。 Does anyone know where it's located instead? 有人知道它的位置吗?

Thanks in advance. 提前致谢。

There is no D8.jar anywhere in build-tools. 构建工具中没有任何D8.jar。 D8 is distributed as a maven artifact instead. D8作为maven工件分发。 It can be downloaded from https://maven.google.com . 它可以从https://maven.google.com下载。 The artifact is named com.android.tools:r8 because D8 is a part of the R8 project. 该工件名为com.android.tools:r8因为D8是R8项目的一部分。 The jar contains both R8 and D8 commandline interfaces, so, in theory, it can be downloaded and used from a commandline like: java -cp r8.jar:<...dependency jars> com.android.tools.r8.D8 <D8 arguments here> java -cp r8.jar:<...dependency jars> com.android.tools.r8.R8 <R8 arguments here> However this artifact jar has a lot of dependencies and if you want to use it outside of the gradle-based build then it is easier to build r8/d8.jar executable jars from the sources by yourself. jar包含R8和D8命令行接口,因此,理论上,它可以java -cp r8.jar:<...dependency jars> com.android.tools.r8.D8 <D8 arguments here> java -cp r8.jar:<...dependency jars> com.android.tools.r8.R8 <R8 arguments here>下载和使用,如: java -cp r8.jar:<...dependency jars> com.android.tools.r8.D8 <D8 arguments here> java -cp r8.jar:<...dependency jars> com.android.tools.r8.R8 <R8 arguments here>然而,这个工件jar有很多依赖项,如果你想在它之外使用它基于gradle的构建然后你可以更容易地从源代码构建r8 / d8.jar可执行jar。 The instruction how to do it is at https://r8.googlesource.com/r8/ . 有关如何操作的说明,请访问https://r8.googlesource.com/r8/ The resulting jars are self-contained (all deps bundled in). 由此产生的罐子是独立的(捆绑所有deps)。

The Android Gradle plugin (and, therefore, Android Studio) doesn't depend on the com.android.tools:r8 . Android Gradle插件(以及Android Studio)不依赖于com.android.tools:r8 R8/D8 classes are bundled into com.android.tools.build:builder (one of the libraries that gradle plugin consists of) instead. R8 / D8类被捆绑到com.android.tools.build:builder (其中一个gradle插件包含的库)中。

D8 dexer has become the default compiler in @AndroidStudio 3.1 D8 dexer已成为@AndroidStudio 3.1中的默认编译器

Expect faster and smarter app compilation 期待更快,更智能的应用程序编译

Faster, smarter app compilation is always a goal for the Android tools teams. 更快,更智能的应用程序编译始终是Android工具团队的目标。 That's why we previously announced D8, a next-generation dex compiler. 这就是我们之前宣布下一代dex编译器D8的原因。 D8 runs faster and produces smaller .dex files with equivalent or better runtime performance when compared to the historic compiler - DX 与历史编译器--DX相比,D8运行速度更快,并生成更小的.dex文件,具有相同或更好的运行时性能

Please see comparition beetween DX vs D8 : 请参阅DX与D8之间的比较: 在此输入图像描述

You can always revert to DX for now via this setting in your project's gradle.properties file: 您现在可以通过项目的gradle.properties文件中的此设置始终恢复为DX:

android.enableD8=false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM