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

无法解析符号“AppCompatActivity”

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


当前回答

试试这个。在Android Studio中,将依赖放在build.gradle中。 进入构建—>清洁项目。

这对我很管用。

其他回答

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

只需更改依赖项:

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

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

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

我把它修好了。gradle文件和appcompat依赖文件,比如编译'com.android.support:appcompat-v7:XX.X.X'

将其更改为编译'com.android.support:appcompat-v7:XX.X.+'

然后点击“同步”。如果代码中的其他内容都是正确的,那么所有的红色曲线都应该消失。

在将Android Studio从2.2.3更新到2.3,将Android Gradle插件更新到2.3.0,并将Gradle更新到3.3之后,我得到了AppCompatActivity和许多其他类和方法的Cannot resolve符号错误。

File -> Invalidate Caches / Restart没有解决问题。

首选项->构建,执行,部署-> Gradle显示使用本地Gradle分布选择与Gradle home: /Applications/Android Studio.app/Contents/ Gradle / Gradle -2.14.1和警告显示Gradle位置是不正确的。

通过选择使用默认gradle包装器(推荐)解决了这个问题。 可能只要指向新的本地分销地点也可以。

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

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