skip to Main Content

I have the following setup:

  • Android Studio 2021.3.1
  • gradle: 7.4

Root level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
        google()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.github.spotbugs:spotbugs-gradle-plugin:4.7.1'
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        maven { url 'https://jitpack.io' }
    }
}

Module level build.gradle:

import com.github.spotbugs.snom.SpotBugsTask

buildscript {
    repositories {
        mavenCentral()
        google()
        maven { url 'https://jitpack.io' }
    }
}

plugins {
    id 'com.android.library'
    id 'checkstyle'
    id 'com.github.spotbugs'
}

repositories {
    mavenCentral()
    google()
    maven { url 'https://jitpack.io' }
}

apply from: "publisher.gradle"

<...>

dependencies {
    implementation platform('com.google.firebase:firebase-bom:31.0.0')
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.preference:preference:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.mikepenz:materialdrawer:6.1.2'
    implementation 'com.github.AppIntro:AppIntro:6.2.0'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-database'
    implementation 'com.github.sematext:sematext-logsene-android:3.2.0'
    implementation 'com.github.mik3y:usb-serial-for-android:3.4.6'
}

And while doing gradle sync in Android Studio, I come accross with the following errors:
Dependency failure

First error in text:

:projectName:main: Could not resolve androidx.appcompat:appcompat:1.5.1.
Required by:
    project :projectName

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

As you see above, I’ve declared repositories which contain these dependencies, and I know for sure that these versions exist.

I have already tried: Clearing gradle caches, clearing Android Studio caches and restart, switch to another network, switching off my firewall – nothing helps. And I see that gradle has successfully resolved some dependencies from the full list (for example, materialdrawer and firebase).

Everything was working some time ago – I haven’t opened the project since 2-3 months, and it was working before. And now it’s not, and I cannot understand why. Could someone please help me?

Ah, and by the way, "gradle clean", then "gradle build", which uses same dependencies, is finishing successfully, really assembling the build, on the same instance of Android Studio on the same laptop, only "gradle sync" is failing. Which makes it really unclear for me what’s happening.

2

Answers


  1. In your root level gradle, maybe try adding

    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
    

    So overview

    buildscript {
        val kotlinVersion = "1.7.20"
        repositories {
            maven {
                url = uri("https://plugins.gradle.org/m2/")
            }
            google()
            mavenCentral()
        }
        dependencies {
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    

    Note: My Gradle is in the kts format so it might be different on your end.

    Login or Signup to reply.
  2. I recently had a similar issue with the "facebook-login" dependency caused by "androidx.legacy:legacy-support-v4:1.0.0".

    Disabling the Jetifier in gradle.properties fixed it.

    android.enableJetifier=false
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search