我刚刚尝试使用Android Studio。我已经创建了空白项目,并试图创建扩展AppCompatActivity的活动。不幸的是,Android Studio“说”它
无法解析符号“AppCompatActivity”
我已经编译了“com.android.support:appcompat-v7 . 22.0”。在我的“应用程序”模块的依赖列表和重建项目几次。然而,我只能使用ActionBarActivity。我做错了什么?
我刚刚尝试使用Android Studio。我已经创建了空白项目,并试图创建扩展AppCompatActivity的活动。不幸的是,Android Studio“说”它
无法解析符号“AppCompatActivity”
我已经编译了“com.android.support:appcompat-v7 . 22.0”。在我的“应用程序”模块的依赖列表和重建项目几次。然而,我只能使用ActionBarActivity。我做错了什么?
当前回答
出现这种情况的原因如下:
你没有安装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.
其他回答
今天(4月22日)你可以使用新的AppCompatActivity和支持库v 22.1.0一起发布。
只需更改依赖项:
compile "com.android.support:appcompat-v7:22.1.0"
在这里你可以找到关于这个新类的更多信息。
你可以使用新的appcompat-v7:22.1.+ 只要把这个添加到你的gradle:
编译“com.android.support: appcompat-v7:22.1.1”
这是我在某处找到的救生代码(对不起,不记得起源)。添加它来构建。gradle(模块:应用程序)。您可以将版本替换为相关的版本。
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details -
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '27.1.1'
}
} else if (requested.group == "com.google.android.gms") {
details.useVersion '15.0.0'
} else if (requested.group == "com.google.firebase") {
details.useVersion '15.0.0'
}
}
}
当我将firebase添加到项目中,所有依赖项更新到API 28的最新版本时,错误出现了,尽管我的谷歌服务使用的是4.1.0版本。
当我更新到4.2.0时,我删除了这个错误。
下面这些都不能解决我的问题
重新启动Android 文件>>与Gradle文件同步项目 建立>>清洁项目 重建>>重建项目 >>文件无效缓存/重启
相反,我通过更新appcompat & design dependencies的版本到最新版本来解决这个问题 这样做:去建设。grade (Module:app) >> dependencies部分,然后在appcompat和design dependencies上按ALT + ENTER,然后选择在我的情况下显示的版本,如图所示,它是24.2.1