我刚刚尝试使用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。我做错了什么?
当前回答
试试这个。在Android Studio中,将依赖放在build.gradle中。 进入构建—>清洁项目。
这对我很管用。
其他回答
如果通过gradle file / Invalidate caches和其他IDE工具的软方法不起作用,请使用硬方法:
退出Android Studio 在项目中导航到.idea文件夹 只需重命名libraries文件夹 重新启动Android Studio。现在它应该重新创建libraries文件夹并重新工作。
这对我很管用
Android Studio 3.1.2
Build #AI-173.4720617, built on April 13, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-38-generic
沙赫巴兹·阿里证实,这也行得通
Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-38-generic
moujib确认,它可以在Android Studio 3.2.1上运行
升级你的gradle版本来解决这个问题
转到你的项目级别build.gradle
如果您使用的是旧版本的gradle,请升级到最新版本
classpath 'com.android.tools.build:gradle:4.0.2'
gradle-wrapper.properties
更改distributionUrl为最新版本
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
出现这种情况的原因如下:
你没有安装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.
无法解决符号AppCompatActivity问题。
执行“简单步骤”解决问题。
i)退出Android工作室。
ii)进入您的项目目录。
iii)在你的项目目录中找到。idea文件夹。
iv)删除。idea文件夹。
v)重新启动android studio。
vi)问题将得到解决。
当你在Gradle中添加AndroidX支持时。属性文件。
android.useAndroidX=true
android.enableJetifier=true
如果你使用的Gradle版本大于3.2,传统的Appcompat依赖如。
implementation 'com.android.support:appcompat-v7:27.1.1
不会工作。 将此依赖替换为:
implementation 'androidx.appcompat:appcompat:1.1.0'
此外,在你的类文件中修改AppCompatActivity的导入:
import android.support.v7.app.AppCompatActivity;
:
import androidx.appcompat.app.AppCompatActivity;
Done