问题
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
回答1:
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:...'
}
}
回答2:
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.
回答3:
As of July 2020, you can do as follows:
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
}
来源:https://stackoverflow.com/questions/55065976/how-to-use-latest-r8-shrinker-version