Gradle build failed after updating android studio to 4.2 Beta1

Viewed 1946

I've just updated android studio and can't build my previous project. I've encountered these errors:

class jdk.internal.loader.ClassLoaders$PlatformClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$PlatformClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
class jdk.internal.loader.ClassLoaders$PlatformClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$PlatformClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

I'm kinda new to the android studio my version of java is:

java version "15.0.1" 2020-10-20

and build.gradle file:

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.appName"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//        vectorDrawables{
//            useSupportLibrary true
//        }
    }

    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.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

sorry for the long and messy question. any help would be appreciated.

4 Answers

Try deleting the build/ method and running the daemon again

I had the same error for a while and I recommend to uninstall the previous version. Exprot your settings if needed. Install AS via the exe file in the links, because the zip will produce the same error. I have not tried making a fresh install without uninstalling, but any feedback is appreciated if that method works. Links: https://developer.android.com/studio/archive

Had the same with Android Studio 4.2.1. Uninstalling it and then installing it again helped me.

The error already explains the reasons and fixes to possible problems. if the above mentioned answer by @gtxtreme does not work, try closing android studio and restart your system.

Though it is recommended that you work with stable version of android studio which is 4.1 and leave the testing of beta 4.2 to the experts

Related