简体   繁体   中英

problem with gradle dependencies - recyclerview and cardview

I am trying to implement cardview and recyclerview. But I am getting this error

Failed to resolve: com.android.support:cardview-v7:21.1.1 Show in File Show in Project Structure dialog

Failed to resolve: com.android.support:recyclerview-v7:21.1.1 Show in File Show in Project Structure dialog

this is my dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    implementation 'com.android.support:cardview-v7:21.1.1'
    implementation 'com.android.support:recyclerview-v7:21.1.1'
    implementation 'com.android.support:design:21.1.1'
}

Though it could be version conflicts with appcompat lib.

But , Update your Target APIs to Android 8... see here.

https://developer.android.com/distribute/best-practices/develop/target-sdk

So, your gradle file should look like this.

apply plugin: 'com.android.application'

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

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.2'

    defaultConfig {
        applicationId "your.package"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode = code
        versionName = "ver name"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}


dependencies {
    implementation 'com.android.support:support-v4:28.0.0-rc02'
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support:design:28.0.0-rc02'
    implementation 'com.android.support:cardview-v7:28.0.0-rc02'
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
}

Its because of incorrect version.

implementation 'com.android.support:appcompat-v7:21.0.3' //same as other support library vesion you used.
implementation 'com.android.support:cardview-v7:21.0.3'
implementation 'com.android.support:recyclerview-v7:21.0.3'
implementation 'com.android.support:design:21.0.3'

First of all use the latest implementation dependency prefix instead of the obsolete compile configuration for all your dependencies. Second try to use the latest dependencies which as of now is 27.1.1 (stable). And about the Gradle build error, there must be a connection failure which usually caused by an interrupted internet connection or working with Gradle on offline mode and etc.

Try to check these options to troubleshoot:

  1. Open Android Studio settings (Ctrl + Alt + S on Windows) and type HTTP Proxy on the search field then select the setting from left menu and use the Check connection button with some google repository address like https://dl.google.com/android/repository/repository-12.xml and wait for a Connection successful message, anything else means your proxy or internet connection is somehow the culprit and you need to seek there for a solution.
  2. Make sure you're not using Gradle in offline mode which can be done in Settings> Build, Execution, Deployment> Gradle and the "Offline work" check must be off.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM