'Android- studio error - Cause: unable to find valid certification path to requested target

I got this error on Android Studio while attempting to sync gradle. Cause: unable to find valid certification path to requested target

What I have attempted so far to resolve this:

  1. Deleting/renaming .gradle.
  2. Invalidate caches and restart.

build.gradle

How do I fix this issue?

buildscript {
    ext.compose_version = "1.0.0-rc02"
    ext.kotlin_version = "1.5.10"
    ext.room_version = "2.3.0"
    ext.dagger_hilt_version = "2.37"
    ext.coroutines_version = "1.5.0"
    ext.navigation_components_version = "2.3.5"
    ext.glide_version = "4.11.0"
    ext.java_version = JavaVersion.VERSION_1_8

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_components_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$dagger_hilt_version"
    }

}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app\build.gradle

 plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.chatbot.android"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source