在styles.xml中无法解析符号'Theme'(Android Studio)

182

屏幕截图

从今天开始,Android Studio在styles.xml中找不到AppCompat主题,但代码中的AppCompatActivity可以被识别出来。我的Android Studio版本是2.2.2,Build #AI-145.3360264。

我已经尝试升级到最新的构建工具、编译sdk(25)版本等,但这并没有解决问题。

目前,我已经安装了以下内容(从sdk管理器中):

  • android API:19和23
  • sdk平台工具:25.0.1
  • sdk工具:25.2.3
  • build-tools:23.0.2和25.0.1
  • support repository:40
  • google repository:39

还有其他一些内容,不必在此列出。

app的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.1'
    defaultConfig {
        applicationId "xxx.xxxxxxxx.xxxxxxxxx" //not the real applicationId
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {

        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/RootTools.jar')
    compile 'com.android.support:support-v4:23.+'
    compile 'com.android.support:support-v13:23.+'
    compile 'com.android.support:appcompat-v7:23.+'
    compile 'com.android.support:design:23.+'
    compile 'com.android.support:cardview-v7:23.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    compile 'de.hdodenhof:circleimageview:2.1.0'
}

4
这个项目是否能够编译,还是只有集成开发环境在抱怨?尝试使用“使缓存无效/重新启动”功能。 - Eugen Pechanec
1
清除缓存/重启没有任何改变,只有IDE在抱怨,编译工作正常。可能浪费了您的时间,抱歉,我只是担心错误会消失,并没有意识到编译仍然正常运行 ^^ - FLP
1
我遇到了相同的错误,但编译正常。 - Pablo Cegarra
10
当其他所有解决方案都失败时,这个对我很有帮助。 - Tabish
1
刚遇到这个问题(在Android studio 3.1.3中)。移除 appcompat-v7 并在重新添加之前进行同步有所帮助。让我们一起点赞并期待在 issuetracker.google.com/issues/67790757 上的更新。 - sunadorer
24个回答

3
我遇到了和这个问题类似的情况,只是我使用的是2.2.3版本的Studio。以下是解决我的问题的方法:
在我的项目级别的gradle中,我有以下代码:
classpath 'com.android.tools.build:gradle:2.3.0-alpha2' (这是更新studio后的结果)
我将其替换为:
classpath 'com.android.tools.build:gradle:2.2.3'
我认为你应该寻找与你的gradle配置兼容的classpath。

2

在将Firebase链接到我的应用程序后,我遇到了同样的问题。更新应用程序模块中的build.gradle即可解决问题,更新为:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.8.0'

1
我在将我的Android Studio从2.2.2升级到2.3 Canary版本时也遇到了同样的问题。虽然新的beta版本2.3已经发布,但它仍在使用2.2.3的gradle插件,这是稳定版本。
所以只需在build.gradle项目级别的buildscript中将classpath依赖项从alpha更改为2.2.3并进行同步。它将解决问题,或根据您的渠道版本更改为更合适的版本。
有关Gradle的更多信息,请查看此Gradle Recipes for android Ken Kousen - Gradle Summit 2016。

https://www.youtube.com/watch?v=4L6wHTVmxGA


1
我的问题通过删除文件夹中的.gradle文件并在Android Studio中重新导入项目来解决。

1
从项目文件夹中删除.idea和.gradle,然后与gradle文件同步,这样就可以了。

1

我的解决方案(刚刚在Android Studio 2022.1.1中成功)是将应用程序模块的build.gradle文件中的这行(或类似的行)注释掉:

implementation 'com.google.android.material:material:1.8.0'

然后将此文件与Gradle同步(“立即同步”),然后取消注释该行并再次同步。


1

@Daniel Wilson在其中一个答案中发表了评论,解决了我的问题。我想将其作为答案添加以引起更多人的注意。

compileSdkVersiontargetSdkVersion从26更新到27(然后当然要更新依赖项),这样就消除了我的错误。


1
我遇到了一个奇怪的问题,具体表现如下:
  • Android Studio 版本为 3.1.2
  • support lib 版本为 27.0.0
我通过以下步骤解决了这个问题:
  1. 将 support lib 版本改为 27.1.0,并点击“Sync Project with Gradle Files”,然后这个错误就消失了
  2. 将 support lib 版本改回 27.0.0,并点击“Sync Project with Gradle Files”,然后这个错误再次没有出现

1

我也遇到了Android Studio 3.1的问题,同步无法帮助我。

然后我切换回了

`'com.android.support:design:27.1.0'` from : `'com.android.support:design:27.1.1'`

并在 gradle.properties 中添加 android.enableBuildCache=false 以禁用构建缓存。


1
在较新版本的Android Studio中,我们被要求使用“AppCompat”。一些用户取消勾选并仍然使用Theme.AppCompat。这就造成了这个错误。我也遇到过同样的问题。
解决方案是在你的build.gradle(app)中添加这行代码。
compile 'com.android.support:appcompat-v7:26.1.0'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接