Search code examples
javaandroidgradleandroid-gradle-pluginbuild.gradle

Android Studio suggests upgrading Gradle to 8.2.1, but can't


I'm trying to upgrade Gradle to the most recent version. I know 8.2.1 is possible- not only does Android Studio offer it as an option, but also the Gradle website even says that 8.2.1 is no longer the most current version (8.3 is). However, when it goes and looks for 8.2.1 in the maven repositories, it can't find it. I also downloaded 8.2.1, and put a link to it in the Gradle-wrapper.properties, and that doesn't help either. It gives me this error when I attempt to sync Gradle:

  • What went wrong: A problem occurred configuring root project 'StarterApp'.

Could not resolve all files for configuration ':classpath'. Could not find com.android.tools.build:gradle:8.2.1. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.2.1/gradle-8.2.1.pom

I looked inside the google repository, and OF COURSE it doesn't have the most recent version of Gradle on its website. SMH Any ideas on how to get Android Studio to find the correct information so it can finish upgrading to 8.2.1 (or heck, even 8.3 would be even better, though that hasn't been offered by Android Studio I know it exists) would be nice.

Here are some of my files: build.gradle (Project):

buildscript {
            ext.kotlin_version = '1.8.20'
    repositories {
        google()
    }
    dependencies {
       classpath 'com.android.tools.build:gradle:8.2.1'
    }
  }

allprojects {
    repositories {
        mavenLocal()
        maven { url "https://jitpack.io" }
    }
}
buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

build.gradle (Module):

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.starter'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.starter"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs += '-Xlint:deprecation'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.exifinterface:exifinterface:1.3.6' // check for the latest version online
    implementation 'androidx.activity:activity:1.7.2'
    implementation 'androidx.activity:activity-ktx:1.7.2'
    implementation 'androidx.fragment:fragment:1.6.1'
    implementation 'com.google.android.gms:play-services-maps:18.1.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
    implementation 'androidx.navigation:navigation-fragment:2.7.2'
    implementation 'androidx.navigation:navigation-ui:2.7.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}'

gradle.properties:

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

gradle-wrapper.properties:

#Tue Aug 08 17:09:22 PDT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=file:///C:/Gradle/gradle-8.2.1-bin.zip

zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Solution

  • You're getting the Android Gradle Plugin (AGP) mixed up with Gradle.

    AGP is the com.android.tools.build:gradle dependency that you're adjusting. The most recent versions are 8.1, 8.2.0-beta3, and 8.3 is upcoming. You should not set it to 8.2.1; it's separate from the Gradle version.

    The Gradle version is specified in gradle/wrapper/gradle-wrapper.properties. You should only change

    distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
    

    to 8.2.1 to update the Gradle version. Don't download it directly; let the distributionUrl take care of it for you using services.gradle.org.

    I'd also recommend you look into the latest build structure (whether in Groovy or Kotlin). You can see what that looks like by creating a new project in the latest version of Studio that you're using.