如何解决如何修复 Android Studio 中的“Android 资源链接失败”错误?
我刚刚开始学习和使用“Android Studio”软件并编辑一个项目。花了太长时间才弄清楚如何处理它。我刚刚修复了很多错误,现在我知道了很多关于错误的事情,但是有一件事情发生在我身上,这让我发疯了! 我无法修复此错误,也不知道这有什么问题。这是错误:
> Task :app:processReleaseResources Failed
AGPBI: {"kind":"error","text":"Android resource linking Failed","sources":[{"file":"C:\\Users\\****\\.gradle\\caches\\transforms-2\\files-2.1\\b635fd2d4b36b21da676271add72c19b\\material-1.4.0-alpha01\\res\\values\\values.xml"}],"original":"C:\\Users\\****\\.gradle\\caches\\transforms-2\\files-2.1\\b635fd2d4b36b21da676271add72c19b\\material-1.4.0-alpha01\\res\\values\\values.xml: AAPT: error: style attribute 'android:attr/contextPopupMenuStyle' not found.\n ","tool":"AAPT"}
AGPBI: {"kind":"error","original":"C:\\Users\\****\\.gradle\\caches\\transforms-2\\files-2.1\\b635fd2d4b36b21da676271add72c19b\\material-1.4.0-alpha01\\res\\values\\values.xml: AAPT: error: style attribute 'android:attr/dialogCornerRadius' not found.\n ","original":"C:\\Users\\****\\.gradle\\caches\\transforms-2\\files-2.1\\b635fd2d4b36b21da676271add72c19b\\material-1.4.0-alpha01\\res\\values\\values.xml: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.\n ","tool":"AAPT"}
Execution Failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking Failed
C:\Users\****\.gradle\caches\transforms-2\files-2.1\b635fd2d4b36b21da676271add72c19b\material-1.4.0-alpha01\res\values\values.xml: AAPT: error: style attribute 'android:attr/contextPopupMenuStyle' not found.
在错误文本中解决的文件不在我的项目文件夹中,并且确保它是 gradle 的缓存文件夹!试图清除缓存、重建项目、从文件中删除代码行等,但没有任何效果! 希望有人能帮我解决这个问题。
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsversion '29.0.3'
defaultConfig {
applicationId "com.troup.platform"
minSdkVersion 19
targetSdkVersion 21
versionCode 78
versionName '5.7'
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
dexOptions {
jumboMode true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
// Or,if you prefer,you can continue to check for errors in release builds,// but continue the build even when errors are found:
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
ndkVersion '22.0.7026061'
}
dependencies {
implementation filetree(include: ['*.jar'],dir: 'libs')
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.github.chrisbanes.photoview:library:1.2.4'
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
implementation 'com.mikhaellopez:circularimageview:3.2.0'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.mediarouter:mediarouter:1.2.2'
implementation 'androidx.browser:browser:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-ads:19.7.0'
implementation 'com.google.firebase:firebase-messaging:21.0.1'
implementation 'com.google.firebase:firebase-analytics:18.0.2'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation 'com.google.android.gms:play-services-ads:19.7.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.android.billingclient:billing:3.0.2'
implementation 'com.google.android.exoplayer:exoplayer:2.7.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation "com.google.android.material:material:1.4.0-alpha01"
implementation files('libs/YouTubeAndroidplayerApi.jar')
}
dependencies {
implementation 'com.android.support:appcompat-v7:+'
}
apply plugin: 'com.google.gms.google-services'
- 操作系统:Windows 10
- Android Studio 版本:4.1.2
解决方法
显然,您的日志提示您有关错误
未找到样式属性 'android:attr/contextPopupMenuStyle'
。
资源文件夹中的样式文件中缺少此样式属性。
,您的项目中似乎缺少样式。如果您正在学习和复制其他项目,请检查其 res/values/styles.xml
文件并与您的进行比较。否则,您需要创建这些样式。
问题出在这里:
defaultConfig {
targetSdkVersion 21
}
attribute android.R.attr.contextPopupMenuStyle
was not added until API level 24,因此您必须至少定位 24 个材料组件库才能访问该属性。
对我来说,我使用 android material lib (com.google.android.material:material:1.x),我想在 Android api 级别 21 上测试应用程序,即使我是在 api 29 上构建的
所以我改变了
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
到
android {
compileSdkVersion 21
defaultConfig {
minSdkVersion 19
targetSdkVersion 21
这给了我同样的错误,
这是错误的,因为该库要求在 api 29 上构建应用程序,如 https://material.io/develop/android/docs/getting-started#2-compile-your-app-with-android-10
所述所以我将 compileSdkVersion 改回 29,问题消失并在 API 21 上运行应用
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。