3

I had an app that was working fine, but after updating to the latest version of flutter which is 2.8.1 it started showing errors regarding gradle files.

The error is:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find core-1.6.0.aar (androidx.core:core:1.6.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar
   > Could not find core-1.6.0.aar (androidx.core:core:1.6.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar
   > Could not find tracing-1.0.0.aar (androidx.tracing:tracing:1.0.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/tracing/tracing/1.0.0/tracing-1.0.0.aar
   > Could not find versionedparcelable-1.1.1.aar (androidx.versionedparcelable:versionedparcelable:1.1.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/versionedparcelable/versionedparcelable/1.1.1/versionedparcelable-1.1.1.aar
   > Could not find versionedparcelable-1.1.1.aar (androidx.versionedparcelable:versionedparcelable:1.1.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/versionedparcelable/versionedparcelable/1.1.1/versionedparcelable-1.1.1.aar
   > Could not find annotation-experimental-1.1.0.aar (androidx.annotation:annotation-experimental:1.1.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/annotation/annotation-experimental/1.1.0/annotation-experimental-1.1.0.aar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 58s
Exception: Gradle task assembleDebug failed with exit code 1

As you can see android studio can't find some files online, but actually when I follow the links provided in the error, I can download these files but as a .zip format not .aar

Now usually when I encounter such errors I simply download the files manually and place them in their respective folders, which we can get to from the error it self, for instance:

if we took a look at the first file that is core-1.6.0.aar we can see that the folder of it is androidx.core\core\1.6.0 and inside that folder android studio generates another folder with a random name like 7664385a7e39112b780baf8819ee880dcd3c4094, so the full path is like so:

C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\androidx.core\core\1.6.0\<here goes the folder with the random name>

But for the files mentioned above android studio didn't generate any folders, so I have no idea what to do with them, where should I put them? or is there any way to resolve the error and get rid of it?

My android\app\build.gradle file:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.bkh.pharmart"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

My android\build.gradle file:

buildscript {
    ext.kotlin_version = '1.6.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

Thanks in advance.

3
  • 1
    I have same problem . did you find any solution? Commented Jan 12, 2022 at 7:24
  • no, the workaround was to downgrade flutter Commented Jan 12, 2022 at 22:22
  • 1
    thank you . my brother . my flutter upgraded to 2.8 and I think my answer can you. Commented Jan 13, 2022 at 6:08

2 Answers 2

2

I faced this issue yesterday. and after 3 hours. I found a way . close Android Studio and
remove C:\Users\<USER>\.gradle folder (or Rename it)

and Re Build Project with a Good VPN

I prefer VPN with Cisco Any connect Protocol .


this is my build.gradle and I add some repository may be it can help you.

buildscript {
    repositories {
//        google()
//        mavenCentral()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
//        google()
//        mavenCentral()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer, I'll try it and tell you if it works for me too
1

Update latest to the latest version of Gradle, then run

flutter clean 
flutter run

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.