android.support.v7.widget.CardView 未被识别
android.support.v7.widget.CardView not being recognized
我正在尝试为我的应用程序使用较旧的依赖项,但在 XML 文件中它无法识别布局并给我一个错误。此外,build.gradle 文件编译完美,但在 cardview 和 recyclerview 的实现下方显示红色下划线。
Xml 文件:
附上我需要但尚未被识别的图片。
https://i.stack.imgur.com/bZIbm.jpg
build.gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testsuccess"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:21.+'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-database:4.2.0'
}
我什至尝试过实施
implementation 'com.android.support:cardview-v7'
implementation 'com.android.support:recyclerview-v7'
但它迫使我迁移到 Androidx 库并且不允许我使用旧库。
注意:布局是项目中的附加文件。
添加:
implementation 'androidx.cardview:cardview:1.0.0'
这将引入 androidx.cardview.widget.CardView
,这是您的布局要使用的内容。
如果您想使用旧的 class 名称,您需要使用
从 gradle.properties 文件中禁用 androidx
android.useAndroidX=false
android.enableJetifier=false
强制禁用 androidx。
或
不想禁用 androidx。
然后替换这一行
来自
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
至
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
这在 AndroidX 中可以正常工作。
我正在尝试为我的应用程序使用较旧的依赖项,但在 XML 文件中它无法识别布局并给我一个错误。此外,build.gradle 文件编译完美,但在 cardview 和 recyclerview 的实现下方显示红色下划线。
Xml 文件: 附上我需要但尚未被识别的图片。 https://i.stack.imgur.com/bZIbm.jpg build.gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testsuccess"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:21.+'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-database:4.2.0'
}
我什至尝试过实施
implementation 'com.android.support:cardview-v7'
implementation 'com.android.support:recyclerview-v7'
但它迫使我迁移到 Androidx 库并且不允许我使用旧库。 注意:布局是项目中的附加文件。
添加:
implementation 'androidx.cardview:cardview:1.0.0'
这将引入 androidx.cardview.widget.CardView
,这是您的布局要使用的内容。
如果您想使用旧的 class 名称,您需要使用
从 gradle.properties 文件中禁用 androidxandroid.useAndroidX=false
android.enableJetifier=false
强制禁用 androidx。
或
不想禁用 androidx。
然后替换这一行
来自
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
至
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
这在 AndroidX 中可以正常工作。