'Could not resolve recyclerview-v7' Error,

2019-09-22 13:54发布

问题:

I am working on Android since 2 years. I never faced issue like this. After updating Android Studio and com.android.tools.build:gradle:3.1.3, i am facing this issue.

Issue: Could not resolve RecyclerView-v7

This is a silly issue which make me stuck for 1 hour. This only happens in com.android.tools.build:gradle:3.1.3.

Project level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: rootProject.file('dependencies.gradle')

buildscript {
    repositories {
        jcenter()

        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

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

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

App level build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "in.kpis.upkeep"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
    }
    dataBinding {
        enabled = true
    }
    buildTypes {
        debug {
            versionNameSuffix "-T"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            versionNameSuffix "-R"
        }
    }

    useLibrary 'org.apache.http.legacy'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileOptions {
        targetCompatibility rootProject.ext.targetCompatibilityVersion
        sourceCompatibility rootProject.ext.sourceCompatibilityVersion
    }
}
def SUPPORT_LIB_VER = '27.1.1'
def SDP_VERSION = '1.0.5'
def BUTTER_KNIFE_VER = '8.8.1'
dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$SUPPORT_LIB_VER"
    implementation "com.android.support:design:${SUPPORT_LIB_VER}"
    implementation "com.android.support:cardview-v7:$SUPPORT_LIB_VER"
    implementation "com.android.support:recyclerview-v7:${SUPPORT_LIB_VER}"
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.0.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.4'
    implementation "com.jakewharton:butterknife:${BUTTER_KNIFE_VER}"
    annotationProcessor "com.jakewharton:butterknife-compiler:${BUTTER_KNIFE_VER}"
    implementation 'com.wdullaer:materialdatetimepicker:3.6.0'
    implementation "com.intuit.sdp:sdp-android:$SDP_VERSION"
    implementation "com.intuit.ssp:ssp-android:$SDP_VERSION"
    implementation group: 'org.simpleframework', name: 'simple-xml', version: '2.7.1'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.github.esafirm.android-image-picker:imagepicker:1.13.0'
    implementation 'com.github.bumptech.glide:glide:4.5.0'
}

Exported versions

ext {
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    minSdkVersion = 15
    targetSdkVersion = 27
    sourceCompatibilityVersion = JavaVersion.VERSION_1_8
    targetCompatibilityVersion = JavaVersion.VERSION_1_8
}

I downgraded build.gradle to make this working but that's not a solution. Someone know this issue?

回答1:

This is because You have updated all compile to implementation in your build.gradle "App level"

To solve this - Go to your build.gradle (Project level)

and You just need to add google() on top of jcenter() inside repositories blockes.

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

Take this code and put inside your build.gradle "Project Level"



回答2:

Add google() to your allprojects >> repositories block. You don't need to add maven { url 'https://maven.google.com' } and consecutive maven block.



回答3:

The fact that it works using lower version of Gradle, means that MOST PROBABLY it's not because of repository.

Maybe it's because of your buildToolsVersion. I didn't see you put it in your build.gradle. Please make sure it is 27.0.3.

Have you check in your SDK Manager? You can make sure that your SDK Manager didn't use older version of SDK Build Tools.

SDK Tools -> Check Show Package Details (on left bottom) -> Install Build Tools version 27.0.3, and uninstall older Build Tools version