Installing Retrolambda in Android Studio

De-uglify your Android code.

Retrolambda lets you use lambdas in Android Studio!

In build.gradle (Project: YourProj), you’ll need to add the line

classpath 'me.tatarka:gradle-retrolambda:3.7.0'

to dependencies {}. For example:

...
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'me.tatarka:gradle-retrolambda:3.7.0'
    }
}
...

At the end of the same file, add the line

apply plugin: 'me.tatarka.retrolambda'

Then, to "build.gradle (Module: app)" you’ll need to add the lines:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

to android {}. For example:

android {
    ...
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('...'), '...'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}
									

Awesome! Now sync your gradle files and test things by pasting this into your code:

new Thread(() -> {
    Log.d("THREAD", "Hello World\n");
}).start();

Check the Github page if you have problems.

ANDROID
blog content post