java.lang.NoSuchMethodError: No static method metafactory

How can I resolve this error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.uddeshika, PID: 4061
    java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
        at com.google.firebase.components.ComponentDiscovery.discoverLazy(ComponentDiscovery.java:112)
        at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:418)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:299)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2429)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2399)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
        at android.app.ActivityThread.installProvider(ActivityThread.java:8063)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:7599)
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7483)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7440)
        at android.app.ActivityThread.access$1400(ActivityThread.java:301)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2148)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8506)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)

My Build Gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.uddeshika"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-firestore:23.0.0'
    implementation "com.firebaseui:firebase-ui-auth:7.1.1"
    implementation "com.firebaseui:firebase-ui-firestore:7.1.1"
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

Solution 1:

Add this to your build.gradle(app):

android
{
   ...

   compileOptions 
   {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
   }

   ...
}