Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use latest R8 Shrinker version

Because of a bug, I have used local jar file for R8 Shrinker (as recommended by R8 team) with adding the classpath to top gradle.build :

classpath files($..../R8.jar/$)

Now regardless of any update to the Android Studio the Gradle build still using the old version of R8 that I have used before V. 1.4.55

Recently I'm seeing that they have published newest version: V. 1.4.69 https://r8.googlesource.com/r8/

So my question is: How to configure gradle to tell to use latest version of R8, because I don't see any documentation about this

like image 731
EAK TEAM Avatar asked Mar 08 '19 15:03

EAK TEAM


People also ask

How do I enable R8 on my Android?

To enable R8, open build. gradle module app file and add this piece of code inside the buildTypes . The code inside the release{} block means that this will be applied to the release build version of your application. If you launch the app in the emulator, this code is not executed.

What is minifyEnabled in Android?

minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.

What is enableR8?

Enable more aggressive optimizations R8 includes a set of additional optimizations that are not enabled by default. You can enable these additional optimizations by including the following in your project's gradle.properties file: android.enableR8.fullMode=true.

What is shrinkResources?

– android developer. Jun 12, 2015 at 10:47. 1. minifyEnabled enables proguard which removes unused classes/code and shrinkResources removes unused resources (pngs, xmls, mostly introduced by libraries which you don't fully utilize).

What is the latest version of R8 code Shrinker?

R8, the new code shrinker from Google, is available in Android studio 3.3 beta 05 November 2018 Labels: #Android, Android App, R8

How to reduce the size of your Android app using R8 shrinking?

R8 shrinking will reduce the size of your app through the following techniques: Tree shaking removes unused code and structures the static analysis of code. It also removes unreachable code and removes uninstantiated types. Let’s say you’re using a library like OkHttp.

What is the new code Shrinker available in Android Studio?

R8, the new code shrinker from Google, is available in Android studio 3.3 beta. 05 November 2018.

What is code shrinking and how does it work?

Code shrinking helps reduce the size of your APK by getting rid of unused code and resources as well as making your actual code take less space (also known as minification or obfuscation). That's why we're investing in improving code shrinking to make it faster...


3 Answers

You should add the following:

buildscript {
    repositories {
        maven {
            url 'http://storage.googleapis.com/r8-releases/raw'
        }
    }
    dependencies {
        classpath 'com.android.tools:r8:1.4.71'  //Must be before the Gradle Plugin for Android. - Or any other version
        classpath 'com.android.tools.build:gradle:...'
     }
}
like image 141
EAK TEAM Avatar answered Oct 02 '22 06:10

EAK TEAM


There is currently no way of referring to the latest version of R8. Using a specific version of R8 should only be used to work around bugs, and when that fix reaches the Android Gradle plugin the reference to a specific version of R8 should be removed to just use the R8 built into the Android Gradle plugin.

This is to limit the use of specific R8 versions, to avoid developers staying on older versions, and encourage developers to the use of the version bundled with Android Gradle plugin. This limits the number of different versions used by developers.

like image 27
sgjesse Avatar answered Oct 02 '22 06:10

sgjesse


As of July 2020, you can do the following:

Add this to your build.gradle file (for the project, not app)

 dependencies {
        classpath 'com.android.tools:r8:2.0.88'  // Must be before the Gradle Plugin for Android.
       // in addition to everything else that was here ....
    }

The whole file should look like this, for reference:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools:r8:2.0.88'  // Must be before the Gradle Plugin for Android.
        classpath 'com.android.tools.build:gradle:4.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 27
Avi Pars Avatar answered Oct 02 '22 06:10

Avi Pars