2

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 Answers2

0

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'
MexiCano
  • 271
  • 1
  • 11
  • Thanks but it shows ERROR: Failed to resolve: com.google.android.material:material:1.2.0-alpha06. –  Jun 10 '20 at 18:22
  • @MexiCano Did you check the dependencies in the question? All the dependencies of the first block are already included in the build.gradle with updated versions. Also I can't understand why you are suggesting alpha releases when beta and stable versions are available. – Gabriele Mariotti Jun 10 '20 at 18:48
  • I checked dependencies and updated android studio but again it shows same error. –  Jun 12 '20 at 20:30
0

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.

KalanaChinthaka
  • 323
  • 4
  • 13