【问题标题】:No resource found that matches the given name (at 'dialogCornerRadius' with value '?android:attr/dialogCornerRadius')未找到与给定名称匹配的资源(在 'dialogCornerRadius' 处,值为 '?android:attr/dialogCornerRadius')
【发布时间】:2018-08-16 16:47:18
【问题描述】:

谁能帮助我为什么在以下内容中出现错误?

错误:(7, 41) 未找到与给定名称匹配的资源(在 'dialogCornerRadius' 的值为 '?android:attr/dialogCornerRadius')。

apply plugin: 'com.android.application'

//Add these lines
def Base_URL = '"' + WEBServiceBaseURL + '"' ?: '"Define BASE URL"';
def SMS_Base_URL = '"' + WEBServiceBaseSMSURL + '"' ?: '"Define SMS BASE URL"';

android.buildTypes.each { type ->
    type.buildConfigField 'String', 'Base_URL', WEBServiceBaseURL
    type.buildConfigField 'String', 'SMS_Base_URL', WEBServiceBaseSMSURL
}

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.bla.bla"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled  true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:+'
    compile files('libs/jxl-2.6.jar')
    compile 'com.google.gms:google-services:+'

    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
}

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

【问题讨论】:

  • 我注意到半小时前的一个相同错误。您最近是否更新了任何库版本? stackoverflow.com/questions/49170669/…
  • 不,我没有更新任何东西!
  • 尝试将 buildToolsVersion 更改为 26.0.2
  • 还是同样的错误。
  • @NileshRathod 直到。从来没有意识到这是一个特定于 P 的东西。谢谢

标签: android gradle dependencies build-error


【解决方案1】:

我通过选择

解决了这个问题

API 27+:Android API 27,P 预览版(Preview)

在项目结构设置中。下图显示了我的设置。构建应用程序时出现的 13 个错误已经消失。

【讨论】:

  • @Jon,它没有给出任何错误。感谢您的回答,但我无法在我的设备中运行,因为它提供了 minSdk(API 27,P 预览版)! = deviceSdk(API 24) 知道可以做什么吗?
  • @PavanPyati 你的 build.gradle 文件中有哪些值? compileSdkVersion 'android-P' buildToolsVersion '26.0.2'
  • @Jon 是的,和你提到的一样。
  • 构建成功,但我无法在设备中安装此 apk。安装apk时遇到的问题是:解析包时出现问题。
  • 此处相同 - 无法在设备上安装 - 失败 [INSTALL_FAILED_OLDER_SDK:... 需要开发平台 P,但这是发布平台]
【解决方案2】:

compile 'com.android.support:design:+'这一行改为compile 'com.android.support:design:26.+'

由于+ 告诉它“获取最新版本”,构建项目时的 gradle 依赖项正在拉取最新版本。 26.+ 将告诉构建过程仅更新最新版本的 v26。

或者为了更加具体和安全,将行更改为特定版本,完全避免使用+。即compile 'com.android.support:design:27.1.0'

【讨论】:

  • @PepaHruška 添加了关于如何使用特定版本号的说明
【解决方案3】:

在大家的帮助下,我可以解决这个问题并在较低版本中运行应用程序。

我更新的 build.gradle 如下所示。

特别感谢所有天才!

apply plugin: 'com.android.application'
android.buildTypes.each { type ->
    type.buildConfigField 'String', 'Base_URL', WEBServiceBaseURL
    type.buildConfigField 'String', 'SMS_Base_URL', WEBServiceBaseSMSURL
}

android {
    compileSdkVersion 27
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.dummy.dummy"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled  true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.+'
    compile files('libs/jxl-2.6.jar')
    compile 'com.google.gms:google-services:+'
    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
}

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

【讨论】:

  • 我已经完成了更改。我使用 compileSdkVersion 作为 android-P 和 buildToolVersion 作为 26 。我构建成功但没有安装在设备中。
  • 如果我使用 compileSdkVersion 作为 27 则它不起作用。
【解决方案4】:

忘记动态依赖并用固定的特定版本替换它们:

错误:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:+'
    compile files('libs/jxl-2.6.jar')
    compile 'com.google.gms:google-services:+'

    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
}

正确:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.1.0'
    compile files('libs/jxl-2.6.jar')
    compile 'com.google.gms:google-services:3.1.1'

    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
}

【讨论】:

    【解决方案5】:

    在您的 gradle 中更改以下依赖项:


    compile 'com.android.support:design:+'
    

    到:

    compile 'com.android.support:design:26.1.0'
    

    'com.android.support:appcompat-v7:26.+'
    

    到:

    'com.android.support:appcompat-v7:26.1.0'
    

    请注意,您可以指定任何版本,但请确保它们具有相同的版本。

    这将确保不会创建 values-28.xml 文件。

    【讨论】:

    • 你应该先积累50个声望。
    【解决方案6】:

    设置你的 compileSdkVersion 28 让android studio下载平台文件

    【讨论】:

      【解决方案7】:

      如果在您的应用程序级别 gradle 中使用了 compileSdkVersion = 27,那么它将不起作用。 您必须使用版本 28。

      compileSdkVersion 28 buildToolsVersion '28.0.3'

      【讨论】:

        【解决方案8】:

        在迁移到 AndroidX 失败后出现同样的错误。 我恢复了 Android Studio 所做的所有更改、清理项目、无效缓存/重新启动以及许多其他事情,但没有运气。 最后发现Android Studio在gradle.properties中添加了两行:

        android.useAndroidX=true
        android.enableJetifier=true
        

        删除这些行后一切恢复正常。

        【讨论】:

          【解决方案9】:

          我都试过了,但是没有用。最后,在我将平台/android/project.properties 中的目标更改为 28 后,它起作用了。

          改变

          target=android-26
          

          target=android-28
          

          谢谢

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-06-28
            • 2018-08-23
            • 2019-07-14
            • 1970-01-01
            • 2015-03-16
            • 1970-01-01
            相关资源
            最近更新 更多