ERROR: Failed to resolve: cardview Affected Modules: app

Viewed 838

I want to use CardView in my project but it shows ERROR: Failed to resolve: cardview Affected Modules: app,Why?I checked dependencies and updated android studio but again it shows same error

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.dubsmash.volley:library:2.0.1'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
    implementation 'androidx.core:core-ktx:1.4.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0'

}

I can't add cardview. Layout is:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="76dp"
        android:fontFamily="@font/chewy"
        android:text="@string/title"
        android:textSize="36sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.525"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
2 Answers

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'

OR/AND

Add MaterialComponents:

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

Since AndroidX still has some weird bugs, you might solve it updating the android studio to newest version.

Also you can use android.enablejetifier to false in gradle.properties but you will have to use androidx libraries.

Related