我刚刚尝试使用Android Studio。我已经创建了空白项目,并试图创建扩展AppCompatActivity的活动。不幸的是,Android Studio“说”它

无法解析符号“AppCompatActivity”

我已经编译了“com.android.support:appcompat-v7 . 22.0”。在我的“应用程序”模块的依赖列表和重建项目几次。然而,我只能使用ActionBarActivity。我做错了什么?


当前回答

我刚把我的android studio从2.3.2版本升级到3.1.2版本。这个错误就发生了。

我清理项目,重建项目,无效缓存/重新启动,但什么都不工作。

我通过更新appcompat库来解决这个错误

编译“com.android.support: appcompat-v7:23.4.0”

to

编译“com.android.support: appcompat-v7:25.1.1”

在应用程序构建中。gradle文件。

其他回答

今天(4月22日)你可以使用新的AppCompatActivity和支持库v 22.1.0一起发布。

只需更改依赖项:

compile "com.android.support:appcompat-v7:22.1.0"

在这里你可以找到关于这个新类的更多信息。

让我们一步一步来:首先通过使用清洁项目

构建——>清洁

如果这没有帮助,那么使用第二步

文件>缓存失效/重启……

但真正的问题开始时,所有上述选项都不起作用,所以使用您的最终解决方案是关闭项目,并进入项目位置目录和删除

.idea

您现在可以再次打开您的项目。

出现这种情况的原因如下:

你没有安装SDK API(这是我的问题) 你的项目/Android Studio不知道需要的文件在哪里 您的项目引用了不支持AppCompatActivity的过时编译版本 有个错别字

可能的解决方式:

Check your .gradle file to make sure you’re not referencing an outdated version. AppCompatActivity was added in version 25.1.0 and belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1, so do not use any version earlier than this. In your build.gradle (Module: app) file you should have the dependency listed: dependencies { compile 'com.android.support:appcompat-v7:25.1.0' } You may be using a different version, but just make sure you have listed the dependency. Open the SDK manager and download every API 7 or newer. If you were missing the needed API it will fix that issue, and downloading all the newer API’s can save you some hassle later on as well. Check for typos in your import statement. Make sure it doesn’t say “AppCompactActivity” instead of “AppCompatActivity”. Resync your project (File >Sync project with Gradle files) Rebuild your project (Build >rebuild) Clean your project (Build >clean project) Close and restart Android Studio Update Android Studio Regenerate your libraries folder – In Android Studio, view your files in project view. Find the folder YourProjectName >.idea >libraries. Rename the folder to “libraries_delete_me”. Close and reopen Android Studio. Open your project again and the libraries folder should be regenerated with all of the files; you can now delete the “libraries_delete_me” folder.

这真的很疯狂,我尝试了一切,与Gradle文件同步,无效并重新启动android工作室。问题仍然存在。最后一招是删除。idea/libraries文件夹,效果很好。

除了其他答案,在设置中添加下面的dependencyresoltionmanagement。Gradle解决了这个问题。

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

注意:我正在将旧的android项目迁移到AndroidX。在执行所有强制步骤后,此问题已结束,无法解析符号“AppCompatActivity”。在尝试了这里提到的所有其他解决方案后,问题仍未解决。当检查设置。Gradle和添加上面的代码解决了这个问题。