简体   繁体   English

D8和R8 android之间的区别

[英]Difference between D8 and R8 android

As android studio introduced two new tools D8 and R8. 随着android studio推出了两款新工具D8和R8。 As per google documentation D8 is a dex tool and R8 is a progourd tool but as their explanation both are doing almost same thing like below: 根据谷歌文档D8是一个dex工具,R8是一个progourd工具,但由于他们的解释两​​者都做了几乎相同的事情如下:

D8 is a dexer that converts java byte code to dex code. D8是一个将java字节代码转换为dex代码的dexer。

R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code. R8是一个java程序缩小和缩小工具,它将java字节代码转换为优化的dex代码。

It seems both converts java byte code to dex code literally. 它似乎都将java字节代码逐字转换为dex代码。 So, Whats actually they are doing internally in case of converting dex code? 那么,实际上他们在转换dex代码时是在内部做什么的?

D8 dexer and R8 shrinker D8 dexer和R8收缩机

D8->D8 is a dexer that converts java byte code to dex code. D8-> D8是一个将java字节代码转换为dex代码的dexer。

R8->R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code. R8-> R8是一个java程序缩小和缩小工具,它将java字节代码转换为优化的dex代码。

Android developers know that dex compilation is a key step in building an APK. Android开发人员知道dex编译是构建APK的关键步骤。 This is the process of transforming .class bytecode into .dex bytecode for the Android Runtime (or Dalvik, for older versions of Android). 这是将.class字节码转换为Android运行时(或Dalvik,旧版Android)的.dex字节码的过程。 The dex compiler mostly works under the hood in your day-to-day app development, but it directly impacts your app's build time, .dex file size, and runtime performance. dex编译器主要在日常应用程序开发中工作,但它直接影响应用程序的构建时间,.dex文件大小和运行时性能。

The R8 project uses depot_tools from the chromium project to manage dependencies. R8项目使用chromium项目中的depot_tools来管理依赖项。 Install depot_tools and add it to your path before proceeding. 安装depot_tools并将其添加到路径中,然后再继续。

The R8 project uses Java 8 language features and requires a Java 8 compiler and runtime system. R8项目使用Java 8语言功能,需要Java 8编译器和运行时系统。

  • New version number scheme following the SDK Tools revision number. SDK Tools修订号后面的新版本号方案。
  • Support for true debug build. 支持真正的调试构建。 No need to change the value of debuggable in the Android Manifest. 无需在Android Manifest中更改debuggable的值。

    Incremental build will automatically insert debuggable==true while using the "export signed/unsigned application package" will not. 增量构建将自动插入debuggable == true,而使用“export signed / unsigned application package”则不会。 If debuggable=true is set, then release builds will actually do a debug build. 如果设置了debuggable = true,那么发布版本实际上会进行调试构建。

  • Automatic Proguard support in release builds. 发布版本中的自动Proguard支持。 Only need to have a proguard.config 只需要有一个proguard.config

    property in default.properties that points to a proguard config file. default.properties中指向proguard配置文件的属性。

  • Completely rewritten Visual Layout Editor. 完全重写Visual Layout Editor。 This is very much a work in progress. 这是一项非常重要的工作。

    • full drag and drop from palette to layout for all Layout classes. 从调色板完全拖放到所有布局类的布局。
    • Move widgets inside a Layout view, from one Layout view to another and from one layout file to another. 将小部件移动到布局视图中,从一个布局视图移动到另一个布局视图,从一个布局文件移动到另一个

    • Contextual menu with enum/flag type properties. 具有枚举/标志类型属性的上下文菜单。

    • New zoom controls. 新的缩放控件。

I think the introduction of this blogpost is a great resource to answer that question: https://jakewharton.com/r8-optimization-staticization 我认为引入这篇博文是一个很好的资源来回答这个问题: https//jakewharton.com/r8-optimization-staticization

R8 is a version of D8 that also performs optimization. R8是D8的一个版本,也执行优化。 It's not a separate tool or codebase, just the same tool operating in a more advanced mode. 它不是一个单独的工具或代码库,只是在更高级模式下运行的相同工具。 Where D8 first parses Java bytecode into its own intermediate representation (IR) and then writes out the Dalvik bytecode, R8 adds optimization passes over the IR before its written out. 在D8首先将Java字节码解析为其自己的中间表示(IR)然后写出Dalvik字节码的情况下,R8在写出之前在IR上添加优化传递。

  • D8 is a dexer that converts java byte code to dex code.D8 is a replacement for the DX dexer. D8是一个dexer,它将java字节代码转换为dex代码 .D8是DX dexer的替代品。
  • R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code . R8是一个java程序缩小和缩小工具,它将java字节代码转换为优化的dex代码

for more detail... 更多细节......

D8 processes each Java class file individually without looking at the entire program. D8单独处理每个Java类文件,而不查看整个程序。 This makes the conversion to DEX fast, since classes can be processed in parallel, and during development it allows fast recompilation when the code of a class is modified. 这使得转换为DEX的速度很快,因为类可以并行处理,并且在开发期间它允许在修改类的代码时快速重新编译。

On the other hand, R8 (like ProGuard) reads in the entire application and makes changes and optimizations (eg inlining) that require knowing the entire class hierarchy. 另一方面,R8(与ProGuard一样)读入整个应用程序并进行需要了解整个类层次结构的更改和优化(例如内联)。 For instance, R8 will remove unused classes and methods ("tree shaking") and rename classes, methods and fields (except for the application's entry points). 例如,R8将删除未使用的类和方法(“树摇动”)并重命名类,方法和字段(应用程序的入口点除外)。

In Android Studio 3.1, D8 has replaced DX as the tool that converts Java class files to DEX, but R8 has not been enabled yet. 在Android Studio 3.1中,D8已经取代DX作为将Java类文件转换为DEX的工具,但R8尚未启用。

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

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