【问题标题】:ERROR: Failed to resolve: cardview Affected Modules: app错误:无法解决:cardview 受影响的模块:app
【发布时间】:2020-09-30 04:19:03
【问题描述】:

我想在我的项目中使用 CardView 但它显示 ERROR: Failed to resolve: cardview Affected Modules: app,Why? 我检查了依赖项并更新了 android studio 但它再次显示相同的错误

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'

}

我无法添加卡片视图。布局是:

<?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>

【问题讨论】:

标签: android android-studio android-cardview cardview


【解决方案1】:

删除它们

只需这 3 个,您就可以同时使用 RecyclerView 和 CardView 以及一个加号: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'

或/与

添加材质组件:

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

【讨论】:

  • 谢谢,但它显示错误:无法解决:com.google.android.material:material:1.2.0-alpha06。
  • 欢迎您!验证我的回答。 =)
  • @MexiCano 您是否检查了问题中的依赖关系?第一个块的所有依赖项都已包含在更新版本的 build.gradle 中。我也无法理解你为什么在测试版和稳定版可用时建议发布 alpha 版本。
  • 我检查了依赖项并更新了 android studio 但再次显示相同的错误。
【解决方案2】:

由于 AndroidX 仍然存在一些奇怪的错误,您可以将 android studio 更新到最新版本来解决它。

您也可以在gradle.properties 中使用android.enablejetifierfalse,但您必须使用androidx 库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    相关资源
    最近更新 更多