How to fix Failed to resolve error for libraries in Android Studio?

Issue

I develop one android application and after some days show me below error in logcat and not sync project!

I develop one android application and after some days show me below error in logcat and not sync project!

I develop one android application and after some days show me below error in logcat and not sync project!

Show me below error :

app/build.gradle    
Failed to resolve: design   
Failed to resolve: appcompat-v7 
Failed to resolve: cardview-v7  
Failed to resolve: support-vector-drawable  
Failed to resolve: play-services-base-license   

My build.gradle file :

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }

    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.25.4'

    }
}
plugins {
    id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.8.1'
}

apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://maven.google.com' }
}

apply plugin: 'io.fabric'


android {
    compileSdkVersion 27
    buildToolsVersion '28.0.2'
    defaultConfig {
        applicationId "com.app.android"
        minSdkVersion 16
        targetSdkVersion 25

        versionCode 30
        versionName "1.3.1"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

        manifestPlaceholders = [onesignal_app_id: "48ce7653-3dd1-4aef-8439-b159ae8d4fad", onesignal_google_project_number: "REMOTE"]

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations {
        all {
            exclude module: 'httpclient'
            exclude module: 'json'
            exclude group: 'org.apache.httpcomponents'
        }
    }

}

dependencies {
    implementation 'com.android.support:support-v4:27.0.2'
    api fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    api 'com.android.support:appcompat-v7:27.0.2'
    api 'com.android.support:design:27.0.2'
    api 'com.android.support:cardview-v7:27.0.2'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.roughike:bottom-bar:2.+'
    testImplementation 'junit:junit:4.12'
    api 'com.android.support:support-v13:+'
    api 'uk.co.chrisjenx:calligraphy:2.3.0'
    api 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    api 'com.squareup.retrofit2:retrofit:2.3.0'
    api 'com.squareup.retrofit2:converter-gson:2.3.0'
    api 'com.google.code.gson:gson:2.8.1'
    api 'com.squareup.okhttp3:logging-interceptor:3.9.1'
    api 'com.github.bumptech.glide:glide:3.7.0'
    api 'com.github.nkzawa:socket.io-client:0.5.2'
    api 'com.auth0.android:jwtdecode:1.1.1'
    api 'com.airbnb.android:lottie:2.5.0-beta1'
    api 'com.auth0:java-jwt:3.3.0'
    api 'com.github.faruktoptas:FancyShowCaseView:1.0.0'

    api 'com.google.firebase:firebase-core:12.0.1'
    api 'com.google.firebase:firebase-crash:12.0.1'
    api 'com.google.firebase:firebase-messaging:12.0.1'
    api 'com.google.android.gms:play-services-analytics:12.0.1'
    api 'com.google.android.gms:play-services-location:12.0.1'

    api 'com.adjust.sdk:adjust-android:4.12.2'
    api 'com.github.chrisbanes:PhotoView:2.0.0'
    api 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3'
    api 'com.google.zxing:core:3.2.1'

    api('com.crashlytics.sdk.android:crashlytics:[email protected]') {
        transitive = true
    }
    api('com.crashlytics.sdk.android:answers:[email protected]') {
        transitive = true
    }
    api 'com.onesignal:OneSignal:[3.7.1, 3.99.99]'
    api 'com.afollestad.material-dialogs:core:0.9.4.5'
    api 'id.zelory:compressor:2.1.0'
    api 'com.android.support:multidex:1.0.3'
    api 'com.android.support:multidex-instrumentation:1.0.3'
    api 'org.greenrobot:eventbus:3.1.1'
    api 'com.codemybrainsout.onboarding:onboarder:1.0.4'
    api "com.mikepenz:itemanimators:1.0.2"
    api 'jp.wasabeef:recyclerview-animators:2.3.0'
    api 'android.arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'

}

apply plugin: 'com.google.gms.google-services'

project level gradle :

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.1.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

I sure my internet is connected.

How can i fix it?

Solution

Change the order and put google() before jcenter() in build.gradle

WHY? A good explanation is given here

Your final project level build.gradle should look like this

buildscript {
  repositories {
      google()
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.1.3'
      classpath 'com.google.gms:google-services:4.1.0'


      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
  }
}

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

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

Answered By – Ayush Khare

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published