更新支持库版本27.1.0
Android Studio后无法渲染CardView。它显示错误消息为
failed to find style 'cardView Style' in current theme
但是编译没有错误,在手机上看也没有区别。
我已将支持库版本恢复为 27.0.2
并且渲染良好。
支持库或 Android Studio 的问题?如何解决这个问题?
应用级 Gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.tmmmt.tmmmt"
minSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "default"
productFlavors {
dev {
dimension "default"
versionNameSuffix "-dev"
buildConfigField 'String', 'BASE_URL', BASE_URL_DEV
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_DEV]
}
beta {
dimension "default"
versionNameSuffix "-beta"
buildConfigField 'String', 'BASE_URL', BASE_URL_BETA
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_BETA]
}
live {
dimension "default"
buildConfigField 'String', 'BASE_URL', BASE_URL_LIVE
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_LIVE]
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:support-v13:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.google.firebase:firebase-messaging:$play_version"
implementation "com.google.android.gms:play-services-maps:$play_version"
implementation "com.google.android.gms:play-services-location:$play_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.tmmmt.library:arrowtab:1.3'
implementation 'com.github.stfalcon:chatkit:0.2.2'
implementation 'com.amazonaws:aws-android-sdk-core:2.6.16'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.16'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.16'
implementation 'com.orhanobut:logger:2.1.1'
implementation 'com.tmmmt.library:animations:0.6'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
compile('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
/*Fort*/
implementation project(':FortSDKv1.4.1')
implementation 'com.victor:lib:1.0.1'
implementation 'com.shamanland:fonticon:0.1.8'
implementation('com.nispok:snackbar:2.11.0') {
exclude group: 'com.google.android', module: 'support-v4'
}
implementation 'com.google.guava:guava:23.0-android'
implementation 'org.bouncycastle:bcprov-jdk16:1.46'
implementation 'commons-codec:commons-codec:1.10'
/*Fort*/
}
apply plugin: 'com.google.gms.google-services'
项目级 Gradle:
buildscript {
ext.kotlin_version = '1.2.30'
ext.anko_version = '0.10.1'
ext.support_version = '27.1.0'
ext.play_version = '11.8.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:4.3.2"
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://mymavenrepo.com/repo/eDGOo6Dqr4f6uNA0HoWX/"
credentials {
username = 'myMavenRepo'
password = 'tmmmt123'
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
更新:
Android Studio 3.2
没有这样的错误。错误完全消失了。
最佳答案
查看CardView的源码
可以看到构造函数
public CardView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs, 0);
}
已改为
public CardView(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, R.attr.cardViewStyle);
}
并且在库中定义了新的属性cardViewStyle
。我猜出于某种原因,Android Studio 预览版不包括库中此属性的值。我不确定它是否通常会解决库中定义的自定义属性,这是一个错误,或者这是有意的。
解决方法 1
解决主题中的属性(可能仅在调试版本中),这样错误就消失了。 @style/CardView
已在支持库中定义,因此您无需创建样式,只需引用即可。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="cardViewStyle">@style/CardView</item>
</style>
确保在布局预览和干净构建中使用 AppTheme
。
解决方法 2
使用 tools
命名空间添加样式,这样它就不会影响您的生产代码。将记录渲染错误,但您仍会看到 CardView
<android.support.v7.widget.CardView
tools:style="@style/CardView"
...
好消息
Android Studio 3.1 似乎可以正确处理此问题,无需解决方法(但仍会记录布局预览中的错误)。
在 Android Studio 3.2(目前在 Canary channel )上,错误消失了。
关于android - 在当前主题中找不到样式 'cardView Style',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49153215/
相关文章:
kotlin - Kotlin 中的 crossinline 和 noinline 有什么区别?
dictionary - Kotlin 是否有 Map 文字的语法?
kotlin - 在 Android Studio 中构建时如何解决错误 "Failed to re
java - 在 Kotlin 中定义 log TAG 常量的最佳方法是什么?
android - Kotlin - 将 List 转换为 MutableList 的最惯用方式
generics - kotlin 中的 out 关键字是什么
constructor - 如何在 Kotlin 中扩展具有多个构造函数的类?