4

I'm developing a new android application by using androidx libraries, and i need to use cardview in my layout.
so i try to add cardview library to my project but i get this error ERROR: Failed to resolve: cardview

i check answers of Failed: com.android.support:cardview-v7:26.0.0 android, but it doesn't help me
answers like

  • add google() before jcenter()
  • add maven { url "https://maven.google.com" } to repositories

build.gradle(project)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.chavosh.porterageapp"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
    testImplementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'

    // recycler view
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'

    implementation 'androidx.cardview:cardview:1.0.0'

}

build.gradle(moudle)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

gradle.properties has this two line

android.useAndroidX=true
android.enableJetifier=true

error pic

Mahan Vyakti
  • 129
  • 3
  • 10
hassan moradnezhad
  • 455
  • 2
  • 6
  • 26
  • can you please clean build project or invalidate restart android studio. – Mehul Kabaria Apr 19 '19 at 12:16
  • Try to add `android.useAndroidX=true android.enableJetifier=true` in your `gradle.properties` file. Also please check this link: https://stackoverflow.com/questions/52181574/android-failed-to-resolve-cardview-v7 Also please check https://developer.android.com/jetpack/androidx/migrate It can help you more – Ajay Mehta Apr 19 '19 at 12:19
  • @MehulKabaria thanks for your answer. i tried restarting android studio but nothing happens – hassan moradnezhad Apr 19 '19 at 12:59
  • @AjayMehta-Rlogical i just edit the question , thanks but my `gradle.properties` file had `android.useAndroidX=true android.enableJetifier=true` – hassan moradnezhad Apr 19 '19 at 13:04

3 Answers3

12

Just remove them!

With just those 3 you can use both RecyclerView and CardView and a plus as well: ConstraintLayout

implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Luca Nicoletti
  • 2,265
  • 2
  • 18
  • 32
  • No worries :) I also struggled a lot. Question @hassanmoradnezhad did you manually converted to androidX or used the AndroidStudio converter tools? If so, you might want to report a bug to Google stating that the converter hadn't remove those lines from the `build.gradle` file – Luca Nicoletti Apr 19 '19 at 14:03
0

Add MaterialComponents:

implementation 'com.google.android.material:material:1.2.0-alpha06'

See this : https://stackoverflow.com/a/57833454/11720798

-1

Tick download in CardView of Palette/layout to solve this problem

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83