Android - 更新支持库 com.android.support :cardview-v7 to version 27. 0.2 未知属性问题

标签 android attributes android-support-library android-cardview android-studio-3.0

将 android 支持库从版本 27.0.1 更新到 27.0.2 时出现问题

问题类型:将版本从 27.0.1 更改为 27.0.2 后,我的 CardView 会出现问题,因为找不到某些 CardView 属性。

用最简单的方式“解决”这个问题:回到27.0.1版本

但我宁愿用另一种方式解决它,这样我就可以升级到版本 27.0.2

所以我的问题是:

  1. 为什么我会收到这些错误,我该如何解决?

  2. 这是 Lint 中的一种错误,可以在更新的支持库仍然不可用时提出建议吗?最后一个问题是因为如果我查看 SDK 工具 (Android Studio 3.0),然后我发现 Android SDK 平台和 PlatPlatform-Tools 的最实际版本是 27.0.1。

下面详细说说我的情况。

1. **Usage in XML layout file:**

        <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                card_view:cardBackgroundColor="?attr/myCardBackgroundColor"
                card_view:cardCornerRadius="5dp"
                card_view:contentPadding="10dp">


2 .**build.gradle (Project zzz):**

        allprojects {
            repositories {
                jcenter()
                google()
                maven {
                    url 'https://maven.google.com/'
                }
            }
        }


3. **build.gradle (Module:app):**

        apply plugin: 'com.android.application'

        android {
            signingConfigs {
                config {
                    storeFile file('sssssssssssssssssssssssssssssss')
                    keyAlias 'aaaaaaa'
                    keyPassword 'bbbbbbbb'
                    storePassword 'ccccccccc'
                }
            }
        compileSdkVersion 27    
        defaultConfig {
            applicationId "xxx.yyy.zzz"
            minSdkVersion 16
            targetSdkVersion 27

            versionCode dd
            versionName 'dd.ee.ff'

            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

            signingConfig signingConfigs.config

            vectorDrawables.useSupportLibrary = true
        }

        buildTypes {
            release {
                shrinkResources true
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                debuggable false
                jniDebuggable false
                renderscriptDebuggable false
                pseudoLocalesEnabled true
                }
            }

            productFlavors {
            }
        }

        dependencies {

 testImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
                exclude group: 'com.android.support', module: 'support-annotations'
        })
            testImplementation 'junit:junit:4.12'

            implementation fileTree(include: ['*.jar'], dir: 'libs')
            implementation 'org.jetbrains:annotations-java5:15.0'

            implementation 'com.android.support.constraint:constraint-layout:1.0.2'

            implementation 'com.android.support:appcompat-v7:27.0.1'
            implementation 'com.android.support:cardview-v7:27.0.1'
            implementation 'com.android.support:design:27.0.1'
            implementation 'com.android.support:support-annotations:27.0.1'

            implementation 'com.google.android.gms:play-services-location:11.8.0'
            implementation 'com.google.android.gms:play-services-vision:11.8.0'

            implementation 'com.google.firebase:firebase-crash:11.8.0'
            implementation 'com.google.firebase:firebase-core:11.8.0'

    implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') { transitive = true }


            implementation 'me.dm7.barcodescanner:zxing:1.9.8'
        }

        apply plugin: 'com.google.gms.google-services'
        apply plugin: 'io.fabric'



Everything is working OK and as expected.


NOW WHEN I UPGRADE 27.0.1 to 27.0.2:


4. **build.gradle (Module:app)**:

        implementation 'com.android.support:appcompat-v7:27.0.2'
        implementation 'com.android.support:cardview-v7:27.0.2'
        implementation 'com.android.support:design:27.0.2'
        implementation 'com.android.support:support-annotations:27.0.2'

并同步项目,我会收到如下错误:

Error:error: attribute 'xxx.yyy.zzz:cardBackgroundColor' not found.
Error:error: attribute 'xxx.yyy.zzz:cardCornerRadius' not found.
Error:error: attribute 'xxx.yyy.zzz:contentPadding' not found.

当我查看 Gradle 控制台时,我会发现:

Gradle 控制台:

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]

Configuration on demand is an incubating feature.
Could not find google-services.json while looking in [src/debug]
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
Could not find google-services.json while looking in [src/release]
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: /home/user/AndroidStudioProjects/Project/app/google-services.json
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest
:app:fabricGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:app:processDebugResources
AGPBI: {"kind":"error","text":"error: attribute \u0027xxx.yyy.zzz:cardBackgroundColor\u0027 not found.","sources":[{"file":"/home/user/AndroidStudioProjects/Project/app/src/main/res/layout/activity.xml"}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: attribute \u0027xxx.yyy.zzz:cardCornerRadius\u0027 not found.","sources":[{"file":"/home/user/AndroidStudioProjects/Project/app/src/main/res/layout/activity.xml"}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: attribute \u0027xxx.yyy.zzz:contentPadding\u0027 not found.","sources":[{"file":"/home/user/AndroidStudioProjects/Project/app/src/main/res/layout/activity.xml"}],"original":"","tool":"AAPT"}

这有点无聊,因为 Lint 告诉我 CardView 有更新的支持库版本:

A newer version of com.android.support:cardview-v7 than 27.0.1 is available: 27.0.2

现在我按如下方式禁用了这个检查:

    //noinspection GradleDependency
    implementation 'com.android.support:cardview-v7:27.0.1'

已阅读本期:

Failed to resolve: com.android.support:cardview-v7:26.0.0 android

但这并没有给我解决这个问题的任何意义。

我在互联网上阅读了很多文章,但这些与我的问题无关。

最佳答案

你设置了compileSdkVersion为27,但是你在哪里定义了buildToolsVersion

通常看起来像:

compileSdkVersion 27
buildToolsVersion '26.0.2'

关于Android - 更新支持库 com.android.support :cardview-v7 to version 27. 0.2 未知属性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48260053/

相关文章:

android 使用 cursorloader 而不是 managedQuery

java - 以示例应用程序为例并添加 SQLCipher 不起作用

html lang 属性的 html 验证错误

python - Cython 具体化属性?

android - 通过 DAO 方法返回 Map 对象

java - 从 fragment 调用父 Activity 方法

c# - 什么是等效于 modelBuilder 的 HasDefaultValueSql 的 Entity Framework Core 属性?

android - 使用设计支持库的android底部导航菜单中超过3个项目

android - VectorDrawable 使我的应用程序在 Lollipop 5.0.1 中崩溃

android - 设置 SearchView 清除按钮颜色