androidgradlebuildflexboxjcenter

Android Build Failure: Could not find flexbox-2.0.1.aar


When I try to build/run the app I get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform flexbox-2.0.1.aar (com.google.android:flexbox:2.0.1) to match attributes {artifactType=android-aar-metadata, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find flexbox-2.0.1.aar (com.google.android:flexbox:2.0.1).
        Searched in the following locations:
            https://jcenter.bintray.com/com/google/android/flexbox/2.0.1/flexbox-2.0.1.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 13s
Exception: Gradle task assembleDebug failed with exit code 1

Any idea on how to fix this issue?


Solution

  • The reason for the issue is that the dependency flexbox-2.0.1 was hosted on jcenter(), which has been shut down.

    One solution to solve this issue is to remove the jcenter() repository from all of the repositories objects in the build.gradle (Project Level) file and add a mirror repository for it, such as Aliyun Mirror, for example:

    buildscript {
        ext.kotlin_version = '1.8.22'
        repositories {
            google()
            mavenCentral()
    -       jcenter()
    +       maven { url "https://maven.aliyun.com/repository/jcenter" }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.1.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
    -       jcenter()
    +       maven { url "https://maven.aliyun.com/repository/jcenter" }
        }
    }