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

无法解析符号“AppCompatActivity”

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


当前回答

我把我的Gradle 2.3.3更新到4.4,在AppCompatActivity和Cardview上得到了一个错误。我尝试了清洁项目和重建项目。它不会工作,然后我去项目文件夹-> .idea ->创建备份库文件夹并删除它->,然后重建项目,解决了我的问题。

其他回答

如果无效缓存没有帮助,只需关闭项目,然后重新打开它。步骤:

文件>关闭项目 从启动项目列表中删除该项目 关闭Android Studio Open Android Studio 用这个项目打开现有的项目

所以我的同事推动了他们当地的。它破坏了一切。我复制了我的sdk路径从另一个应用程序,并做:

File -> Sync Project with Gradle Files

对我来说,当我更新Gradle构建版本时,这个问题就解决了。不知道为什么?

我将告诉你我是如何在eclipse中解决这个问题的。 从这个链接下载zip文件。https://github.com/dandar3/android-support-v7-appcompat然后解压这个文件,打开项目,在lib文件夹中你会看到一个名为“android-support-v7-appcompat”的jar文件,将这个jar文件添加到你的项目中。这是它。

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

你没有安装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.