gpt4 book ai didi

android - 为什么添加导航组件会导致Gradle错误 “error: resource android:attr/dialogCornerRadius not found.”

转载 作者:行者123 更新时间:2023-12-03 05:32:23 25 4
gpt4 key购买 nike

到目前为止,我的Android应用程序在Android Studio中一直运行良好,但是当我将这些代码行添加到Android Studio项目中以尝试使用Android的导航组件(https://developer.android.com/guide/navigation/navigation-getting-started)时,我一直收到gradle错误。

// Navigation Component
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"

这些错误之一与找不到dialogCornerRadius有关:
.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0.aar/dd9096ce87096c8058dc92354e7f3db2/res/values-v28/values-v28.xml
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.

我在其他帖子上已经读到该问题与我的sdk版本有关,但是我在弄清楚如何更改应用程序build.gradle代码来解决该问题时遇到了麻烦:
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {

def support_version = "26.1.0"
def nav_version = "2.1.0"

// Navigation Component
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"

// Added to avoid dependency conflict
implementation 'com.android.support:support-annotations:27.1.1'

// Added to use tab layouts in MainActivity
implementation 'com.android.support:design:26.1.0'

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation "com.android.support:support-v4:$support_version"
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'
}

当我尝试换线时
 implementation 'com.android.support:support-annotations:27.1.1'

我得到不同的gradle错误。 (我认为这可能可行,因为它似乎是不同版本的所在)。错误是:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

我为此错误中的链接,仍然迷路了。

有人可以帮助我吗?先感谢您。

最佳答案

Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.



您必须使用:
compileSdkVersion 28

另外,您将androidx和支持库混合在一起,这是错误的。
Migrate to androidx

关于android - 为什么添加导航组件会导致Gradle错误 “error: resource android:attr/dialogCornerRadius not found.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58696063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com