android studio 降低项目版本错误,no resource found

本文详细介绍了在Android开发过程中遇到的资源引用错误问题,包括找不到特定属性名称的错误提示,并提供了有效的解决方案,帮助开发者顺利解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error:(6, 21) No resource found that matches the given name: attr 'android:textAlignment'.
Error:(10, 21) No resource found that matches the given name: attr 'android:paddingEnd'.
Error:(10, 21) No resource found that matches the given name: attr 'android:paddingEnd'.
Error:(13, 21) No resource found that matches the given name: attr 'android:paddingStart'.
Error:(17, 21) No resource found that matches the given name: attr 'android:layout_marginEnd'.
Error:(10, 21) No resource found that matches the given name: attr 'android:paddingEnd'.
Error:(23, 21) No resource found that matches the given name: attr 'android:layout_marginStart'.
Error:(26, 21) No resource found that matches the given name: attr 'android:layout_alignParentStart'.
Error:(6, 21) No resource found that matches the given name: attr 'android:textAlignment'.
Error:(10, 21) No resource found that matches the given name: attr 'android:paddingEnd'.
Error:(13, 21) No resource found that matches the given name: attr 'android:paddingStart'.
Error:(26, 21) No resource found that matches the given name: attr 'android:layout_alignParentStart'.
Error:(37, 21) No resource found that matches the given name: attr 'android:layout_toStartOf'.
Error:(40, 21) No resource found that matches the given name: attr 'android:layout_alignParentEnd'.
Error:(44, 21) No resource found that matches the given name: attr 'android:layout_toEndOf'.
Error:(37, 21) No resource found that matches the given name: attr 'android:layout_toStartOf'.
Error:(23, 21) No resource found that matches the given name: attr 'android:layout_marginStart'.
Error:(13, 21) No resource found that matches the given name: attr 'android:paddingStart'.
D:\AndroidStudioProjects\shapecount5\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\22.2.0\res\values-v21\values-v21.xml
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body1'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body2'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Caption'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display1'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display2'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display3'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display4'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Headline'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Menu'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.SearchResult.Subtitle'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.SearchResult.Title'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Subhead'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Title'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Menu'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title.Inverse'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionMode.Subtitle'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionMode.Title'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.TextView.SpinnerItem'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionBar.TabText'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionBar.TabView'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton.CloseMode'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton.Overflow'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.AutoCompleteTextView'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Borderless'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Borderless.Colored'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Small'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ButtonBar'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.CompoundButton.CheckBox'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.CompoundButton.RadioButton'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.DropDownItem.Spinner'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabText'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabText'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabView'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.PopupMenu'.
Error:(213, 21) No resource found that matches the given name: attr 'android:overlapAnchor'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListPopupWindow'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListView'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListView.DropDown'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.PopupMenu'.
Error:(213, 21) No resource found that matches the given name: attr 'android:overlapAnchor'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ProgressBar'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ProgressBar.Horizontal'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.RatingBar'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner.Underlined'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.TextView.SpinnerItem'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Toolbar.Button.Navigation'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.
Error:(120, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(124, 21) No resource found that matches the given name: attr 'android:colorButtonNormal'.
Error:(122, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(123, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(121, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(118, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(119, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(120, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(124, 21) No resource found that matches the given name: attr 'android:colorButtonNormal'.
Error:(122, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(123, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(121, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(118, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(119, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(120, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(124, 21) No resource found that matches the given name: attr 'android:colorButtonNormal'.
Error:(122, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(123, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(121, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(118, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(119, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(127, 21) No resource found that matches the given name: attr 'android:windowElevation'.
Error:(120, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(124, 21) No resource found that matches the given name: attr 'android:colorButtonNormal'.
Error:(122, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(123, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(121, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(118, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(119, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(127, 21) No resource found that matches the given name: attr 'android:windowElevation'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\AndroidSdk\android-sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1

Information:BUILD FAILED



最后发现删除项目的附加库就行了。








<think>我们正在解决Android构建时资源文件中Theme.Dialog相关属性找不到的问题。根据引用内容,错误通常表现为: error: resource style/Theme.AppCompat.Dialog not found error: resource style/Theme.AppCompat.NoActionBar not found 引用[1]和[2]展示了具体的错误信息,引用[3]和[4]提供了一些解决方案。 分析原因: 1. 可能是由于使用的AppCompat库版本不一致或未正确引入。 2. 主题定义中引用了不存在的父主题(如Base.V22.Theme.AppCompat)或版本不匹配。 3. 项目可能错误地迁移到了AndroidX,或者没有正确使用支持库。 解决方案: 根据引用[3]和[4]: - 检查项目的build.gradle文件,确保引入了正确版本的AppCompat库。 - 如果项目未使用AndroidX,需要确保使用支持库(com.android.support)并保持版本一致。 - 如果项目使用了AndroidX,需要确保所有依赖都迁移到了AndroidX。 引用[4]提到,如果手动修改主题文件太麻烦,可以尝试重新创建一个非AndroidX项目(使用legacy support library),并在创建时勾选“Use legacy android.support libraries”。 具体步骤: 步骤1:检查依赖 在app模块的build.gradle中,确保有类似下面的依赖(根据是否使用AndroidX): - 使用支持库(非AndroidX): implementation 'com.android.support:appcompat-v7:28.0.0' // 版本号根据实际情况调整 - 使用AndroidX: implementation 'androidx.appcompat:appcompat:1.0.2' 步骤2:检查主题定义 在res/values/styles.xml(或res/values-v21/styles.xml等)中,检查主题定义。 例如,对于非AndroidX项目,主题可能定义为: <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... </style> 确保父主题存在,且名称正确(如Theme.AppCompat.Dialog,而不是Theme.Dialog)。 步骤3:清理和重建 清理项目(Build -> Clean Project)并重新构建(Build -> Rebuild Project)。 步骤4:如果问题仍然存在,考虑迁移到AndroidX或回退到支持库 - 如果当前项目未使用AndroidX,且不想迁移,确保所有依赖库都使用支持库版本。 - 如果项目已经部分迁移到AndroidX,可能会导致不一致,需要完全迁移或回退。 引用[4]中提到,如果手动修改主题太麻烦,可以重新创建非AndroidX项目(勾选Use legacy android.support libraries)并复制代码。 步骤5:检查Gradle属性 在gradle.properties文件中,检查是否设置了AndroidX属性(如果使用AndroidX): android.useAndroidX=true android.enableJetifier=true 如果不使用AndroidX,则不要设置这些属性(或者设置为false)。 步骤6:检查编译SDK版本 确保compileSdkVersion与使用的AppCompat库版本匹配。例如,使用appcompat-v7:28.0.0时,compileSdkVersion应为28。 示例build.gradle(非AndroidX): android { compileSdkVersion 28 ... defaultConfig { ... targetSdkVersion 28 } } dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' } 如果按照以上步骤操作后问题仍然存在,请提供更多错误信息。 相关问题: 1. 如何解决Android构建时资源链接失败的问题? 2. 如何将项目迁移到AndroidX? 3. 如何回退AndroidX到支持库? 4. 如何正确配置AppCompat库?</think>### 解决 Android 构建错误Theme.Dialog 属性未找到 #### 问题分析 当 Android 构建报错 `Theme.Dialog attributes not found` 时,通常由以下原因导致: 1. **依赖库版本冲突** AppCompat 库版本与编译 SDK 版本不匹配(如引用[3]所示)。 2. **主题定义错误** `qk_game_style.xml` 中引用了不存在的主题(如 `Theme.AppCompat.Dialog`)。 3. **AndroidX 兼容性问题** 项目未正确配置 AndroidX 或遗留支持库(如引用[4]所述)。 --- #### 解决方案 ##### ✅ 方法1:统一依赖版本(推荐) 在 **app/build.gradle** 中确保所有依赖版本一致: ```groovy android { compileSdkVersion 28 // 需与依赖库版本匹配 ... } dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' // 保持版本统一 implementation 'com.android.support:design:28.0.0' // 同级库版本相同 } ``` > 📌 关键点: > - `compileSdkVersion` 必须等于 `appcompat-v7` 的主版本号(例如 `28.0.0` → `28`)[^3]。 ##### ✅ 方法2:修正主题定义 在 **res/values/qk_game_style.xml** 中检查主题继承关系: ```xml <!-- 错误示例:引用不存在的主题 --> <style name="GameTheme" parent="Theme.AppCompat.Dialog"> ... </style> <!-- 正确修改:使用有效父主题 --> <style name="GameTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... </style> ``` > ⚠️ 注意: > 若需使用 `Dialog` 主题,确认已添加 `implementation 'com.android.support:appcompat-v7:xx.x.x'`[^1][^2]。 ##### ✅ 方法3:启用 AndroidX 兼容模式 在 **gradle.properties** 中添加: ```properties android.useAndroidX=true android.enableJetifier=true // 自动转换旧库 ``` 同时在 **build.gradle** 中迁移到 AndroidX: ```groovy dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' // 替代 support 库 implementation 'com.google.android.material:material:1.3.0' } ``` ##### ✅ 方法4:创建新项目(极端情况) 若问题持续,按引用[4]方案重建项目: 1. Android Studio 新建项目时勾选 **☑️ Use legacy android.support libraries** ![](https://example.com/legacy-checkbox.png) 2. 手动复制代码和资源到新项目。 --- #### 调试步骤 1. **清理构建缓存** ```bash ./gradlew clean && ./gradlew --stop ``` 2. **检查依赖树** ```bash ./gradlew app:dependencies > deps.txt ``` 搜索 `appcompat` 确认版本一致性。 3. **验证资源合并** 在 `build/intermediates/merged_res` 中检查最终生成的 `styles.xml`。 > 💡 **预防建议**: > 使用 Android Studio 的 **Refactor > Migrate to AndroidX** 工具自动化迁移[^4]。 --- #### 相关问题 1. 如何解决 `resource style/Theme.AppCompat.NoActionBar not found` 错误? 2. AndroidX 和 Support 库共存时如何处理依赖冲突? 3. 升级 Android Studio 后出现资源链接失败,如何回退兼容? 4. 如何批量修改项目中的旧版 `android.support` 引用? [^1]: Unity resource style/Theme.AppCompat.Dialog (aka xxx:style/Theme.AppCompat.Dialog) not found [^2]: FAILURE: Build failed with an exception... Android resource linking failed [^3]: 定位到错误,属于版本不一致,改成22 [^4]: 重新在 Android Studio 新建项目,勾选 Use legacy
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值