错误:(9,5)错误:找不到资源android:attr/dialogCornerRadius

Dip*_*kar 105 android attr

所以我安装了android studio 3.0.1,并在打开gradle后立即显示以下错误.我尝试添加设计和支持等依赖项,但是徒劳无功.有人能帮助我吗?先感谢您. 在此输入图像描述

它显示找不到某些属性,如dialogCornerRadius和fontVariation设置.

小智 153

由于不匹配compileSdkVersion和库版本而发生此错误.

例如:

compileSdkVersion 27
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
Run Code Online (Sandbox Code Playgroud)

并且还避免在库中使用+符号,如下所示:

implementation 'com.android.support:appcompat-v7:26.+'
Run Code Online (Sandbox Code Playgroud)

使用像这样的精确库版本

implementation 'com.android.support:appcompat-v7:26.1.0'
Run Code Online (Sandbox Code Playgroud)

在库中使用+符号会使构建过程难以收集所需的确切版本,从而使系统不稳定,因此应该不鼓励.


mur*_*glu 47

如果您为AndroidX迁移并出现此错误,则需要将compile SDK设置为Android 9.0(API级别28)或更高级别

  • 有什么方法可以让 androidX 与 sdkcompiled 27 一起使用吗? (2认同)
  • @Phil 在迁移之前,请将您的应用程序更新到最新版本。我们建议更新您的项目以使用支持库的最终版本:版本 28.0.0。这是因为版本 1.0.0 的 AndroidX 工件是与支持库 28.0.0 工件等效的二进制文件。[来源](https://developer.android.com/jetpack/androidx/migrate#precessions)。所以 sdk 27​​ 没有 androidX 的选项 (2认同)

Adn*_*lla 21

我有完全相同的问题.以下主题帮助我解决了这个问题.只需将您的Compile SDK版本设置为Android P.

/sf/answers/3442065301/

  • *注意*,您不必将其定位为28,只需将compileSdkVersion和buildToolsVersion设置为28,然后将targetSdkVersion保留为较低版本 (2认同)

bte*_*n96 15

检查您的依赖项是否+在版本中使用.一些依赖可能正在使用com.android.support:appcompat-v7:+.当新版本发布并且可能破坏功能时,这会导致问题.

对此的解决方案是使用com.android.support:appcompat-v7:{compileSdkVersion}.+或根本不使用+并使用完整版本(例如com.android.support:appcompat-v7:26.1.0).

如果你在build.gradle文件中看不到这一行,请在android studio终端中运行,以概述每个依赖项使用的内容

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath (包括androidtest依赖项)

要么

gradlew -q dependencies app:dependencies --configuration debugCompileClasspath (调试的常规依赖项)

这导致了一些看起来很接近的东西

------------------------------------------------------------
Project :app
------------------------------------------------------------

debugCompileClasspath - Resolved configuration for compilation for variant: debug
...
+--- com.android.support:appcompat-v7:26.1.0
|    +--- com.android.support:support-annotations:26.1.0
|    +--- com.android.support:support-v4:26.1.0 (*)
|    +--- com.android.support:support-vector-drawable:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- com.android.support:support-compat:26.1.0 (*)
|    \--- com.android.support:animated-vector-drawable:26.1.0
|         +--- com.android.support:support-vector-drawable:26.1.0 (*)
|         \--- com.android.support:support-core-ui:26.1.0 (*)
+--- com.android.support:design:26.1.0
|    +--- com.android.support:support-v4:26.1.0 (*)
|    +--- com.android.support:appcompat-v7:26.1.0 (*)
|    +--- com.android.support:recyclerview-v7:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    +--- com.android.support:support-compat:26.1.0 (*)
|    |    \--- com.android.support:support-core-ui:26.1.0 (*)
|    \--- com.android.support:transition:26.1.0
|         +--- com.android.support:support-annotations:26.1.0
|         \--- com.android.support:support-v4:26.1.0 (*)
+--- com.android.support.constraint:constraint-layout:1.0.2
|    \--- com.android.support.constraint:constraint-layout-solver:1.0.2

(*) - dependencies omitted (listed previously)
Run Code Online (Sandbox Code Playgroud)

如果您无法控制更改版本,请尝试强制使用特定版本.

configurations.all {
    resolutionStrategy {
        force "com.android.support:appcompat-v7:26.1.0"
        force "com.android.support:support-v4:26.1.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

根据设置为28.0.0的内容,力依赖性可能需要不同


Ope*_*emi 15

在处理具有多个模块的应用程序时遇到同样的问题,请检查以确保当您将一个模块中的compileSdkVersiontargetSdkVersion增加到 28+ 值时,您也为其他模块执行了操作。

模块被上运行compileSdkVersion 29targetSdkVersion 29在应用程序中的第二模块被上运行compileSdkVersion 27targetSdkVersion 27

将第二个模块更改为也编译并针对 SDK 版本 29 解决了我的问题。希望这可以帮助某人。


Est*_*cas 7

尝试将compileSdkVersion更改为: compileSdkVersion 28

  • 但我希望它是26。 (3认同)

小智 6

这是因为compileSdkVersion,buildToolsVersion和Dependecies实现不匹配,您必须像这样做,我才有28个库

compileSdkVersion 28
targetSdkVersion   28
buildToolsVersion  28.0.3
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
Run Code Online (Sandbox Code Playgroud)

如果我们在少于28个位置使用“任何”,则应发生此错误,因此请尝试全部使用匹配库。


Har*_*han 6

在添加mapbox导航API时遇到了相同的问题,并通过以下方法解决了该问题:file> project Structure,然后将compile sdk版本和build工具版本设置为最新版本。这是屏幕截图: 设置截图

希望能帮助到你。


小智 5

也许现在为时已晚,但我找到了一个解决方案:

你必须在编辑build.gradle要么compileSdkVersion- >到最新的(现在是28).像那样:

android {
compileSdkVersion 28
defaultConfig {
    applicationId "NAME_OF_YOUR_PROJECT_DIRECTORY"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Run Code Online (Sandbox Code Playgroud)

或者您可以更改实施版本:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    api 'com.android.support:design:27.+'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)


小智 5

就我而言,在将 compileSdkVersion 更新为 29 时,我在 AndroidStudio 4.1.1 中收到此错误。

如果你在 build.gradle 中有依赖项目,你需要做的就是在依赖项目的 build.gradle 中更新相同的 compileSdkVersion 。

脚步:

  1. 在 AndroidStudio 的项目视图中单击您的应用程序文件夹。
  2. 选择打开模块设置。
  3. 在项目结构中>>检查有多少个模块?
  4. 如果有多个模块,则还必须更新 compileSdkVersion、buildToolsVersion 和 Project 依赖项。

这对我有用:)