Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between D8 and R8 android

Tags:

As android studio introduced two new tools D8 and 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 is a dexer that converts java byte code to dex code.

R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code.

It seems both converts java byte code to dex code literally. So, Whats actually they are doing internally in case of converting dex code?

like image 214
0xAliHn Avatar asked Mar 29 '18 06:03

0xAliHn


People also ask

What is the purpose of R8 in Android?

Enable shrinking, obfuscation, and optimization 0 and higher, R8 is the default compiler that converts your project's Java bytecode into the DEX format that runs on the Android platform. However, when you create a new project using Android Studio, shrinking, obfuscation, and code optimization is not enabled by default.

What is R8 Android Studio?

R8 is an app shrinking tool that is used to reduce the size of your application. This tool present in Android Studio works with the rules of Proguard. R8 will convert your app's code into optimized Dalvik code.

Should I use R8 or proguard?

R8 is having a faster processing time than Proguard which reduces build time. R8 gives better output results than Proguard. R8 reduces the app size by 10 % whereas Proguard reduces app size by 8.5 %. The android app having a Gradle plugin above 3.4.

What is R8?

The Audi R8 is a mid-engine, 2-seater sports car, which uses Audi's trademark quattro permanent all-wheel drive system. It was introduced by the German car manufacturer Audi AG in 2006.


2 Answers

D8 dexer and R8 shrinker

D8->D8 is a dexer that converts java byte code to dex code.

R8->R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code.

Android developers know that dex compilation is a key step in building an APK. This is the process of transforming .class bytecode into .dex bytecode for the Android Runtime (or Dalvik, for older versions of Android). 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.

The R8 project uses depot_tools from the chromium project to manage dependencies. Install depot_tools and add it to your path before proceeding.

The R8 project uses Java 8 language features and requires a Java 8 compiler and runtime system.

  • New version number scheme following the SDK Tools revision number.
  • Support for true debug build. No need to change the value of debuggable in the Android Manifest.

    Incremental build will automatically insert debuggable==true while using the "export signed/unsigned application package" will not. If debuggable=true is set, then release builds will actually do a debug build.

  • Automatic Proguard support in release builds. Only need to have a proguard.config

    property in default.properties that points to a proguard config file.

  • Completely rewritten 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.
like image 135
Dreamer Avatar answered Sep 18 '22 23:09

Dreamer


I think the introduction of this blogpost is a great resource to answer that question: https://jakewharton.com/r8-optimization-staticization

R8 is a version of D8 that also performs optimization. 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.

like image 45
Fred Porciúncula Avatar answered Sep 20 '22 23:09

Fred Porciúncula