Android - 更新支持库 com.android.support:cardview-v7 到版本 27.0.2 u



将 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 控制台时,我会发现:

格拉德尔控制台:

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:cardBackgroundColoru0027 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:cardCornerRadiusu0027 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:contentPaddingu0027 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'

已经阅读了这个问题:

无法解决:com.android.support:cardview-v7:26.0.0 android

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

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

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

它通常看起来像:

compileSdkVersion 27
buildToolsVersion '26.0.2'

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

最新更新