Java 找不到 android.support.v7.widget.CardView(Android Studio 1.1 预览版)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28302687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.support.v7.widget.CardView could not be found (Android Studio 1.1 Preview)
提问by WildCat
I'm trying to add CardView to my activity as the official sample. But it doesn't work.
我正在尝试将 CardView 作为官方示例添加到我的活动中。但它不起作用。
If I run my project directly, it would lead to java.lang.ClassNotFoundException: android.support.v7.widget.CardView .
如果我直接运行我的项目,它会导致 java.lang.ClassNotFoundException: android.support.v7.widget.CardView 。
采纳答案by Eun
You should add it to your build.gradle
:
您应该将其添加到您的build.gradle
:
dependencies {
...
implementation 'com.android.support:cardview-v7:21.+'
implementation 'com.android.support:recyclerview-v7:21.+'
...
}
回答by Vinay Vissh
Writing my answer to provide:
写我的答案以提供:
1) updated version for
compileSdkVersion 27
.2) usage of
implementation
instead ofcompile
- What's the difference between implementation and compile in Gradle?.3) a complete version number to heed the
Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds..,
warning shown by Android Studio.4) a visual for location of
build.gradle (Module:app)
.5) And because I was not able to write a comment below @Eun's answer.
1) 的更新版本
compileSdkVersion 27
。2) 使用
implementation
而不是compile
-在 Gradle 中实现和编译有什么区别?.3) 一个完整的版本号,以注意
Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds..,
Android Studio 显示的警告。4) 位置的视觉
build.gradle (Module:app)
。5) 因为我无法在@Eun 的回答下面写评论。
You need to paste implementation 'com.android.support:cardview-v7:27.1.1'
in build.gradle[Module:app] located at, for example: MyFirstApplication ->
app ->
build.gradle
您需要粘贴implementation 'com.android.support:cardview-v7:27.1.1'
在的build.gradle[模块:应用程序]位于,例如:MyFirstApplication->
应用->
的build.gradle
Paste in following dependencies clause:
粘贴以下依赖项子句:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
...
}
To open from Android studio itself: (From left side) 1:Project->
Select Androidview ->
Gradle Scripts->
build.gradle (Module: app)
从 Android Studio 本身打开:(从左侧)1:Project->
Select Androidview ->
Gradle Scripts->
build.gradle (Module: app)
That is:
(If the image below is not shown You can find the image here.
Using Android Studio 3.1.4
使用 Android Studio 3.1.4
Edit: Updated version numbers.
编辑:更新版本号。
回答by Vivek Hirpara
dependencies {
...
compile 'com.android.support:cardview-v7:26.+'
compile 'com.android.support:recyclerview-v7:26.+'
...
}
回答by Qamar
I was facing this issue because of the corruption of cached cardview aar.
由于缓存的 cardview aar 损坏,我面临这个问题。
Gradle was picking local cached version of cardview. Also works by changing the library version but make sure you are not overriding configurations.all
Gradle 正在选择 cardview 的本地缓存版本。也可以通过更改库版本来工作,但请确保您没有覆盖configurations.all
Solution:
解决方案:
Close Android Studio,
In windows goto C:\Users\Qamar\.gradle\caches
and search cardview
delete your version folder, clean and rebuild.
关闭 Android Studio,在 windows 中转到C:\Users\Qamar\.gradle\caches
并搜索cardview
删除您的版本文件夹,清理并重建。
Using: Android Studio 3.3 and gradle:3.2.1
使用:Android Studio 3.3 和 gradle:3.2.1
回答by Then Enok
With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX
随着 Android 9.0(API 级别 28)的发布,有一个名为 AndroidX 的支持库的新版本
And the support library will be discontinued...
并且支持库将停止使用...
Add the following to buld.gradle:app
将以下内容添加到 buld.gradle:app
dependencies {
...
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
...
}