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

时间:2018-01-15 09:23:43

标签: 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属性。

To"解决"这以最简单的方式:回到版本27.0.1

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

所以我的问题是:

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

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

  3. 低于我的具体情况。

    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

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

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

2 个答案:

答案 0 :(得分:2)

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

通常看起来像:

compileSdkVersion 27
buildToolsVersion '26.0.2'

答案 1 :(得分:0)

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