Android - 更新支持库 com.android.support:cardview-v7 到版本 27.0.2 未知属性问题

Android - updating support library com.android.support:cardview-v7 to version 27.0.2 unkown attributes issue

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

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

以最简单的方式"resolve":回到版本 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'

已阅读本期:

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

我又在网上看了很多文章,但这些都与我的问题无关。

您已将 compileSdkVersion 设置为 27,但您在哪里定义 buildToolsVersion

通常看起来像:

compileSdkVersion 27
buildToolsVersion '26.0.2'

今天我可以升级到版本 27.1.1,问题似乎已经消失了。好吧,我仍然不知道为什么会这样,但至少看起来已经解决了。