可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
After renaming application package name, Android Studio displayed this error can't resolve symbol AppCompatActivity
Things I tried:
- Clean project
- Clean Android Studio cache
- Clean Gradle cache
- Re-installed IDE
- File-> Invalidate cache/restart
But nothing really helped. The project build successfully, but I can not use syntax highlighting.
I used com.android.support:appcompat-v7:23.1.1
Screenshots
回答1:
Okay, to anybody who might stumble upon this now, Android Studio is very, very, very weird.
Solution : Go to your build.gradle
file and in your dependencies find the appcompat
one, something like compile 'com.android.support:appcompat-v7:XX.X.X'
Change it to compile 'com.android.support:appcompat-v7:XX.X.+'
Then click on Sync Now
on the top right of the editor. All the red squiggly lines should go if everything else in your code is correct.
Then go back to your build.gradle
and change it back to whatever it was and click Sync Now
It should all be fine given that you have the latest version of everything or close to it.
回答2:
Lets get going step by step:
first clean project by using
Build->Clean
if this doesn't helps then use your second weapon
File>Invalidate Caches/Restart...
But the real problem begins when all the above options doesn't works
so use your ultimate weapon close project and go to project location directory and delete
.idea
You can open your project now again. This worked for me and problem comes most often when you are working with VCS. And this problem is not associated with android component classes but also to the libraries, both shows the same error.
回答3:
I was having the same issue, but when I did Invalidate cache/restart
option it worked fine for me.
First try to clear all your build files
Build->Clean
if it doesn't work try this option
File -> Invalidate cache/Restart
回答4:
If methods like
Clean project
Clean Android Studio cache
Clean Gradle cache
Re-installed IDE
File-> Invalidate cache/restart
do not work. use this method to resolve your issue.
Exit Android Studio
Navigate in your project to the .idea folder
Remove .idea folder
Restart Android Studio.
Thats it.
回答5:
For me was enough to go on:
- Tools > ANDROID > SYNC PROJECT WITH GRADLE FILES
回答6:
I was having this exact same issue just a couple minutes ago and fixed it by doing a Build > Rebuild Project
.
Hope it helps.
回答7:
Only removing whole .gradle folder helped me.
回答8:
This is what worked for me, strangely enough:
- Change
implementation 'com.android.support:appcompat-v7:26+'
to implementation 'com.android.support:appcompat-v7:26.0.1'
- Go to File → Invalidate Caches/Restart
- Wait for the Gradle sync to finish on restarting. Once it does you will be prompted to add the Google maven support repository. Click on the corresponding link, and let Gradle resolve the dependencies.
- The errors should be gone now
FWIW, in my case the issue occured after moving my Android Studio installation to a new machine and upgrading to AS 3.1.
回答9:
Deleting the ".idea" folder worked for me. As mentioned above by Vikas Kumar
Then I using this to fix the "SDK location error"
回答10:
I was stuck with this problem and its take me whole day to solve this.Finally i solved this with the following steps
- Close your android studio
- Go to you project folder and look for .idea folder
- Find libraries folder and rename it
- Then start your Android studio and open that project again.
Thats it.
回答11:
I had the same issue and the following worked for me
File -> Invalidate cache/Restart
There is some kind of caching issue that is happening. If such kind of issue appears try this since most of the time it will work :D
回答12:
In Android Studio 3.1.2, I have the same issue After renaming application package name. The following worked for me:
Deleting the ".idea" folder, Then File -> Invalidate Caches/Restart
.
回答13:
I've updated appcompat
library from version 25.0.1
to 25.1.0
In gradle:
from: com.android.support:appcompat-v7:25.0.1
to: com.android.support:appcompat-v7:25.1.0
Everything works well now.
回答14:
i have this problem while using the android studio on ubuntu 16.04 go to File>invalid cache/Restore>Invalidate and Restart that works fine for me
回答15:
Go to your build.gradle file and in your dependencies find the appcompat one, something like compile 'com.android.support:appcompat-v7:25.X.X'
Change it to compile 'com.android.support:appcompat-v7:25.3.+'
Then click on Sync Now on the top right of the editor.
Then go back to your build.gradle and change it back to whatever it was and click Sync Now
This worked for me.
回答16:
When all your dependencies and SDK tools are in-line and it still is giving sync error. Add this code in your build.Gradle
and sync it:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Also like to point, before doing this I tested all tricks mentioned here. But only this worked for my Android (2.3) - Feb'17 release.
回答17:
This working for me, on macOS:
go to,
Android Studio -> Preferences -> Appearance & Behavior -> System Settings
-> Android SDK -> SDK Platforms
And download Android SDK Platform XX and Sources for Android XX. Where XX es the value of compileSdkVersion on your gradle (Module:app)
on Windows the route is:
File -> Settings... -> Appearance & Behavior -> System Settings
-> Android SDK -> SDK Platforms
回答18:
If all attempts failed (invalidate cache, clean and rebuild, restart,...), close Android Studio (maybe just close the project), run any file manager, go to project folder, find .idea/libraries folder and delete its content (list of xml files). After new start AS or opening project the problem should be resolved.
回答19:
head over to build.gradle(module app)
if you hover your mouse over to com.android.support:appcompat
a popup will say new version is available
just replace in the existing version number with the new version number
press sync now
and you are good to go
p.s nothing else worked for me on 2 pc's
回答20:
I've noticed that Android Studio 3.1 doesn't pull in the support libraries seamlessly. Here's how to trigger it. Update the support library version to 27.x.x
newer version (you can get the new version info by mouse hover over the version number next to implementation under dependencies ) manually in the module's build.gradle
file under dependencies. Then re-sync the project. Find the Visual Solution(Image) from this Link
回答21:
You got error like
1.First you have to clean project
after that same issue got then
2.check library minimum
compile "com.android.support:appcompat-v7:22.1.0"
Check library does not use two or more times
Remove multiple time usage of library dependency
- Clean and Rebuild Project to a got solution
回答22:
With the new Release of android studio 3.1.3, you must put this code inside build.gradle.
implementation 'com.android.support:design:23.4.0'
回答23:
This usually happens when you open any old project. Open your Build.gradle (app module) file and update the dependencies to the latest version which you can find in any recently created project or create a new project and copy the dependencies. Sync and then clean your project.
EX: Older versions--> compile 'com.android.support:appcompat-v7:24'
Update to latest version--> implementation 'com.android.support:appcompat-v7:28.1.1'
回答24:
If the methods via gradle file / "Invalidate caches" do not work, use this way:
- Navigate in your project to the .idea folder
- Just Rename the libraries folder
- Restart Android Studio. It will recreate the libraries folder and work again.
回答25:
Guys I know this is gonna sound stupid but I only switched my project like I had 2 projects in my system so I opened the other project when it was completely ready I clicked on open to open my actual project and it worked so just try to switch projects and re open it, this should sort out your issue.
回答26:
Easy
- Open app level
build.gradle
- Remove appcompact-v7 dependency & Sync.
- Add dependency again & Sync.
Error is no more! :)
Before
After
回答27:
Close your project using FILE -> CLOSE PROJECT and then Open, worked for me fixed all the issues.
回答28:
I tried deleting the .idea folder, Clean Build, Validate Caches / Restart, changing Build Tools vers...
None of them worked for me.
I solved this error with selecting the red underlined codes then pressing Alt+Enter and selecting the Import Class option.
It changes the imports to **androidx.core.*******.
If you do this to all your red underlined codes your errors should have resolved.
回答29:
This sometimes happens when you import some other projects in your IDE.
In that case try Building your project 2 to 3 times it automatically gets resolved.
For Rebuild you need to follow the following path:
Build-> Rebuild Project