I have installed Android Studio version 1.0.1. I have imported my projects from eclipse and it works fine.
Then I deleted a module and reimported it into my Android Studio project. The gradle build says "BUILD SUCCESSFUL" but it pops up an alert window with the message
Failed to complete Gradle execution.
Cause:
Already disposed: Module: 'MYMODULENAME'
I can't start my app now. Any idea what I can do?
Edit:
I solved the problem with the following instructions:
Switch project view from Android to Project
Remove entry include 'MYMODULENAME' in settings.gradle
The blue box in the module symbol don't show. Then you can delete the module in the context menu
Import the module
Note: this is purely an IDEA/AS issue, gradlew clean | Build > Clean | Build > Rebuild will just waste your time.
Most of the solutions here are blind stabbings in the dark. Here's what I found to be the root cause:
Some of the .iml files may be missing (maybe because we deleted it),
check if the module erroring has .iml.
If it is missing, check if .idea/modules.xml has an entry for that module
While syncing I noticed that IDEA/AS tries to put a new duplicate entry into .idea/modules.xml while there's already one. This duplicate entry is probably disposed of twice while the sync tries to reset the modules in memory.
Quick Solution: In order to make it work the easiest is to delete .idea/modules.xml along with the .iml files. Additionally may worth deleting .idea/modules/ folder if it exists. Restart Android Studio (no need to clear cache) and force a Gradle sync from Gradle view or toolbar to recreate the files.
I figured out this problem by:
./gradlew clean
Restart Android Studio
Simplest solution. (Try this first).
Quit and Restart Android studio. (Quit not close)
Build > Clean your project if needed.
works for me:
File -> Invalidate Caches / Restart... -> Invalidate and Restart
Sometimes gradlew clean or Invalidate Cache and Restart does not help, because these methods do not clean Android Studio specific files by themselves.
In this case, close AS and remove .idea directory and .iml file in a root project where settings.gradle file exists. This will make AS rebuild from the fresh ground.
For me this happened when i deleted a module and built a new one with the same package name
Solution:
Clean & Restart Studio
In the left pane, change to "Project" view.
Delete MYMODULENAME.iml
For an alternative solution, check if you added your app to settings.gradle successfully
include ':app'
For me this happened when I removed a module and tried to build the project:
Simple solution was to Invalidate the cache & Restart.
Android Studio>File>Invalidate Caches>Invalidate & Restart
Had a similar issue when working with RN components in my Android project and the only way to get around this issue was to ignore the gradle project.
To do this:
Click on the gradle tab on the right hand side of AS
Right click the gradle module which is causing an issue
Click "Ignore Gradle Project"
Perform a gradle sync which should be successful now
If you need this module perform the 4 above steps again, this time when right click on the gradle project it'll show "Unignore Gradle Project"
Gradle sync should now work
No idea what causes this but I've had this happen to me when using React Native Maps.
Note: If you're still having issues following this. Try to refresh the gradle project which was causing issues.
If gradle clean and/or Build -> Clean Project didn't help try to re-open the project:
Close the project
Click "Open an existing Android Studio project" on the "Welcome to Android Studio" screen
Select gradle file to open
Warning Be aware it's a destructive operation - you're going to loose the project bookmarks, breakpoints and shelves
below solution works for me
Delete all .iml files
Rebuild project
For Solve this issue take it this simple steps.
Find the .idea folder in your Android studio under the Folder Project.
In .idea --> Find this one. .idea/.modules
Simple Delete that .modules folder and restart Your studio.
when it reopens gradle sync Automatically and also recreate .modules folder and files.
Error has gone !
I also face this problem sometimes. Click on gradle console in bottom bar of android studio, at right side. It will show the exact error in logs. My problem was that I had compile SDK 22 and imported appcomact library was of sdk 23.
I had the same problem,
after delete some gradle files (of aws)
i solved it by mark them "ignore gradle"
I believe it is not the best answer but it solve it for me
Gradle (at the right bar)--> right click on the problematic gradle --> ignore
Although the accepted answer didn't work for me (unfortunately I can't leave a comment), it led me in the right direction.
in .idea/libraries i found that there were some duplicate xml files (the duplicates were named with a 2 before the _aar.xml bit).
deleting those, restarting android studio and sync fixed the error
I was having this issue because gradle and Android Studio were using a different path for the jvm. In the Event Log there was an option for AS and gradle to use the same path. Selecting this and then doing an invalidate cache & restart resolved the issue for me.
In my case, same as in this question, it happened because I had my project in a symbolic link directory. After reopening the project in the real directory and reconfiguring gradle (File -> Sync with Gradle files) the problem went away. Shame on you, Android Studio!
Related
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
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.
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.
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
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.
The issue could be import reference, try changing it.
From:
import android.support.v7.app.AppCompatActivity;
To:
import androidx.appcompat.app.AppCompatActivity;
For me was enough to go on:
- Tools > ANDROID > SYNC PROJECT WITH GRADLE FILES
I was having this exact same issue just a couple minutes ago and fixed it by doing a Build > Rebuild Project.
Hope it helps.
Only removing whole .gradle folder helped me.
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.
Deleting the ".idea" folder worked for me. As mentioned above by Vikas Kumar
Then I using this to fix the "SDK location error"
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
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.
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
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
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.
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
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.
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
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.
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
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'
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.
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.
Easy
Open app level build.gradle
Remove appcompact-v7 dependency & Sync.
Add dependency again & Sync.
Error is no more! :)
Before
After
Close your project using FILE -> CLOSE PROJECT and then Open, worked for me fixed all the issues.
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.
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.
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.
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'
Open build.gradle file and in your dependencies and
Change file with
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
This worked for me..
I'm importing twitter4j in AndroidStudio, using the following in my build.gradle:
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile files('libs/twitter4j-core-3.0.4.jar')
}
The project compiles fine, and I can create twitter objects without a problem. However, in Android studio, anything referencing that library shows "cannot resolve symbol" and displays in red. What do I need to do to get Android Studio to recognize the library?
I have already tried rebuilding the project, ./gradlew clean, and closing and re-opening my project.
No idea if this will work or not but my only thought so far: right click the jar file in file tree within AS and select "Add as library..."
EDIT: You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
EDIT 2: This fix should work for all similar incidents and is not a twitter4j specific resolution.
Try changing the order of dependencies in File > Project Structure > (select your project) > Dependencies.
Invalidate Caches didn't work for me, but moving my build from the bottom of the list to the top did.
This is what worked for me.
In the Project panel, right click on the project name, and
select Open Module Settings from the popup menu.
then change the Compile SDK Version to the minimum version available (the minimum sdk version you set in the project).
wait for android studio to load everything.
It will give you some errors, ignore those.
Now go to your java file and android studio will suggest you import
import android.support.v4.app.FragmentActivity;
Import it, then go back to Open Module Settings and change the compile sdk version back to what it was before.
Wait for things to load and voila.
For mine was caused by the imported library project, type something in build.gradle and delete it again and press sync now, the error gone.
I also had this issue with my Android app depending on some of my own Android libraries (using Android Studio 3.0 and 3.1.1).
Whenever I updated a lib and go back to the app, triggering a Gradle Sync, Android Studio was not able to detect the code changes I made to the lib. Compilation worked fine, but Android Studio showed red error lines on some code using the lib.
After investigating, I found that it's because gradle keeps pointing to an old compiled version of my libs.
If you go to yourProject/.idea/libraries/ you'll see a list of xml files that contains the link to the compiled version of your libs. These files starts with Gradle__artifacts_*.xml (where * is the name of your libs).
So in order for Android Studio to take the latest version of your libs, you need to delete these Gradle__artifacts_*.xml files, and Android Studio will regenerate them, pointing to the latest compiled version of your libs.
If you don't want to do that manually every time you click on "Gradle sync" (who would want to do that...), you can add this small gradle task in the build.gradle file of your app.
task deleteArtifacts {
doFirst {
File librariesFolderPath = file(getProjectDir().absolutePath + "/../.idea/libraries/")
File[] files = librariesFolderPath.listFiles({ File file -> file.name.startsWith("Gradle__artifacts_") } as FileFilter)
for (int i = 0; i < files.length; i++) {
files[i].delete()
}
}
}
And in order for your app to always execute this task before doing a gradle sync, you just need to go to the Gradle window, then find the "deleteArtifacts" task under yourApp/Tasks/other/, right click on it and select "Execute Before Sync" (see below).
Now, every time you do a Gradle sync, Android Studio will be forced to use the latest version of your libs.
When i lived to this problem(red color codes but they work correctly) in my project;
As first, i made it that (File -> Indicate Cashes) --> (Invalidate and Restart).
As last, i resync my build.gradle file in my app. After problem was resolved.
Invalidate Caches / Restart didn't work for me this time.
Found a solution like this:
Remove the compile *** or implementation *** line in build.gradle.
Clean and rebuild. Errors should be raised here.
Add the line in step 1 back to build.gradle.
Clean and rebuild.
Weird...
This problem happened for me when my Glass project was not using the SDK installed in Android Studio's default location. I was using another location I had previously from ADT, since I was trying to avoid re-downloading everything. Once I pointed the project back to the SDK location in Android Studio's install location the problem went away.
I had this problem for a couple of days now and finally figured it out!
All other solutions didn't work for me btw.
Solution: I had special characters in my project path!
Just make sure to have none of those and you should be fine or at least one of the other solutions should work for you.
Hope this helps someone!
I had the very same problem recently with Android Studio 1.3. The only working solution was to remove the .gradle and .idea folders and re-import the project into Android Studio.
For those, who tried the accepted answer and have no success,
I tried also the accepted answer and did not work for me. After that, I updated my project with the repository and synchronized the project and the could not resolve warnings are gone.
Invalidate Caches didn't work for me (this time). For me it was enough changing the gradle and syncing again. Or https://stackoverflow.com/a/29565362/2000162
If nothing else helped, you could do as Android Studio suddenly cannot resolve symbols recommends:
Exit Android Studio
Back up your project
Delete all the .iml files and the .idea folder
Relaunch Android Studio and reimport your project
In my case, I had created a new file using the GUI and defined an interface within the file. I kept getting this symbol error because the file was not a "java" file. It had no extension on it at all.
After modifying the file extension to ".java", the system correctly finds the symbols.
In my case the jar file did not have a META-INF/MANIFEST.MF file. After adding one, it worked!
For my case working with AndroidStudio 2.2.3 the solution was to change the gradle wrapper/distribution to use local one in the Gradle Settings (despite of being "recommended").
This worked for me--
(File -> Indicate Cashes) --> (Invalidate and Restart).
I tried Invalidate cache/restart or clean Project -> rebuild project. These didn't work for me.
The final solution was open Project window on the left side of IDE, under Project mode, delete .gradle and .idea folder, THEN you can invalidate caches and restart. This fixed it.
Change compile to implementation in the build.gradle.
Changing the language injection settings worked for me.
Place the cursor on any of the red underlined code and Alt + Enter
Now select Language Injection Settings and a window will open as shown below.
Uncheck the selected option and click Ok
Hope this helps somebody.
It happened to me when I removed the whole files in .gradle/caches, then studio downloaded the dependences. The dependences not showed in the External Libraries but I can build App successfully. rebuild clean Invalidate and Restart have no effect. I solved the problem by the steps:
Close Android Studio completely
Remove .idea package in your project
Restart Android Studio
I have tried this but nothing worked for me:
Invalidate Caches / Restart
Changing the order of dependencies
Sync project with Gradle Files
Clean -> Rebuild Project
In my case, just do:
Delete all files in .idea/libraries folder
Rebuild Project
For me I updated gradle-wrapper.properties into 4.4
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I found easiest way
Identify the library which is causing syntax error in Studio.
For Example if AppCompatActivity is showing error then you will perform below operation on AppCompat Dependency.
Remove dependency which is showing syntax error & Sync.
Add again & Sync.
That's It, error gone!
Before
After
None of the answers above works for me.
After a lots of attempts, I upgraded com.android.tools.build:gradle in Project/build.gradle from 2.3.0 to 3.0.1, and it works.
I guess the version of the com.android.tools.build:gradle should be match to the version of AndroidStudio, and my AS version is 3.2.1
I tried all of the posted solutions and none of them worked for me. (Though invalidate caches does normally. This time it made no difference). After trying everything posted here the "Error cannot resolve" were still present. And the project did build and run successfully, only the IDE seemed to be confused, not the actual app or device.
My Version of Android Studio is 2021.3.1:
The solution that did finally work for me was updating the "Android Gradle Plugin Version" configuration inside of File -> Project Structure.
It was originally 3.2.1 when it wasn't working. I updated it to 3.5.3 because I have another project that was working fine and it was on that setting.
After making this change and then sync'ing gradle the symbols not resolved error goes away and the IDE once again knows what those classes are.
Closing all files and closing Android Studio works for me.
You need to restart Android Studio.
I had created a project with Android Studio and pushed it to bitbucket. After few weeks now I have cloned it on different machine to resume my work. I imported the project in Android Studio and now I keep getting this error.
Migrate Project to Gradle?
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
More Information about migrating to Gradle.
Don't show this message again.
I have the gradle directory in my project. I tried using the option of use local gradle distribution and pointed it to downloaded gradle-1.10 but I still keep getting the same error.
First of all I would remove following files/directories from your project-folder:
bin/
build/
.idea/
.gradle/
projectname.iml
Then try to import the project again in AndroidStudio. This usually works for me, and to avoid that in the future, adjust the .gitignore file properly.
If the first tip does not help: have you tried downloading a more recent gradle (1.12) locally and point to that directory? (Don't point AndroidStudio to download, but do it yourself first).
You are not using a gradle-wrapper are you?
If you haven't started coding in your new machine, the simplest way would be to just delete your project directory, and use "import from VCS".
Not worth the time to find the "solution", trust me. I tried. Almost 2 years since you asked the question, and people are still getting the issue, then this problem is obviously not worth solving.
Most probably you have git checkout a parent directory of a working android project.
Close freshly checked git project
Open Project
Navigate to the git checkout directory
Select a sub directory inside the git checkout project and that is the intended android project for you
I ran into the same problem. For me the problem was my sttings.gradle was cleared. After adding incude: 'modulename'. It worked for me
I fixed this issue with the following steps:
Make sure that the following two files are in your project directory. If not, create a new one with reference of your other Android projects. These are default auto-generated files.
settings.gradle
build.gradle
If it is still showing any errors when you open your project, restart your project by selecting file/(invalidate /restart).
I had the same problem and I managed to fix it by invalidating caching and restart File - > Invalidate caches and restart
I'm importing twitter4j in AndroidStudio, using the following in my build.gradle:
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile files('libs/twitter4j-core-3.0.4.jar')
}
The project compiles fine, and I can create twitter objects without a problem. However, in Android studio, anything referencing that library shows "cannot resolve symbol" and displays in red. What do I need to do to get Android Studio to recognize the library?
I have already tried rebuilding the project, ./gradlew clean, and closing and re-opening my project.
No idea if this will work or not but my only thought so far: right click the jar file in file tree within AS and select "Add as library..."
EDIT: You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
EDIT 2: This fix should work for all similar incidents and is not a twitter4j specific resolution.
Try changing the order of dependencies in File > Project Structure > (select your project) > Dependencies.
Invalidate Caches didn't work for me, but moving my build from the bottom of the list to the top did.
This is what worked for me.
In the Project panel, right click on the project name, and
select Open Module Settings from the popup menu.
then change the Compile SDK Version to the minimum version available (the minimum sdk version you set in the project).
wait for android studio to load everything.
It will give you some errors, ignore those.
Now go to your java file and android studio will suggest you import
import android.support.v4.app.FragmentActivity;
Import it, then go back to Open Module Settings and change the compile sdk version back to what it was before.
Wait for things to load and voila.
For mine was caused by the imported library project, type something in build.gradle and delete it again and press sync now, the error gone.
I also had this issue with my Android app depending on some of my own Android libraries (using Android Studio 3.0 and 3.1.1).
Whenever I updated a lib and go back to the app, triggering a Gradle Sync, Android Studio was not able to detect the code changes I made to the lib. Compilation worked fine, but Android Studio showed red error lines on some code using the lib.
After investigating, I found that it's because gradle keeps pointing to an old compiled version of my libs.
If you go to yourProject/.idea/libraries/ you'll see a list of xml files that contains the link to the compiled version of your libs. These files starts with Gradle__artifacts_*.xml (where * is the name of your libs).
So in order for Android Studio to take the latest version of your libs, you need to delete these Gradle__artifacts_*.xml files, and Android Studio will regenerate them, pointing to the latest compiled version of your libs.
If you don't want to do that manually every time you click on "Gradle sync" (who would want to do that...), you can add this small gradle task in the build.gradle file of your app.
task deleteArtifacts {
doFirst {
File librariesFolderPath = file(getProjectDir().absolutePath + "/../.idea/libraries/")
File[] files = librariesFolderPath.listFiles({ File file -> file.name.startsWith("Gradle__artifacts_") } as FileFilter)
for (int i = 0; i < files.length; i++) {
files[i].delete()
}
}
}
And in order for your app to always execute this task before doing a gradle sync, you just need to go to the Gradle window, then find the "deleteArtifacts" task under yourApp/Tasks/other/, right click on it and select "Execute Before Sync" (see below).
Now, every time you do a Gradle sync, Android Studio will be forced to use the latest version of your libs.
When i lived to this problem(red color codes but they work correctly) in my project;
As first, i made it that (File -> Indicate Cashes) --> (Invalidate and Restart).
As last, i resync my build.gradle file in my app. After problem was resolved.
Invalidate Caches / Restart didn't work for me this time.
Found a solution like this:
Remove the compile *** or implementation *** line in build.gradle.
Clean and rebuild. Errors should be raised here.
Add the line in step 1 back to build.gradle.
Clean and rebuild.
Weird...
This problem happened for me when my Glass project was not using the SDK installed in Android Studio's default location. I was using another location I had previously from ADT, since I was trying to avoid re-downloading everything. Once I pointed the project back to the SDK location in Android Studio's install location the problem went away.
I had this problem for a couple of days now and finally figured it out!
All other solutions didn't work for me btw.
Solution: I had special characters in my project path!
Just make sure to have none of those and you should be fine or at least one of the other solutions should work for you.
Hope this helps someone!
I had the very same problem recently with Android Studio 1.3. The only working solution was to remove the .gradle and .idea folders and re-import the project into Android Studio.
For those, who tried the accepted answer and have no success,
I tried also the accepted answer and did not work for me. After that, I updated my project with the repository and synchronized the project and the could not resolve warnings are gone.
Invalidate Caches didn't work for me (this time). For me it was enough changing the gradle and syncing again. Or https://stackoverflow.com/a/29565362/2000162
If nothing else helped, you could do as Android Studio suddenly cannot resolve symbols recommends:
Exit Android Studio
Back up your project
Delete all the .iml files and the .idea folder
Relaunch Android Studio and reimport your project
In my case, I had created a new file using the GUI and defined an interface within the file. I kept getting this symbol error because the file was not a "java" file. It had no extension on it at all.
After modifying the file extension to ".java", the system correctly finds the symbols.
In my case the jar file did not have a META-INF/MANIFEST.MF file. After adding one, it worked!
For my case working with AndroidStudio 2.2.3 the solution was to change the gradle wrapper/distribution to use local one in the Gradle Settings (despite of being "recommended").
This worked for me--
(File -> Indicate Cashes) --> (Invalidate and Restart).
I tried Invalidate cache/restart or clean Project -> rebuild project. These didn't work for me.
The final solution was open Project window on the left side of IDE, under Project mode, delete .gradle and .idea folder, THEN you can invalidate caches and restart. This fixed it.
Change compile to implementation in the build.gradle.
Changing the language injection settings worked for me.
Place the cursor on any of the red underlined code and Alt + Enter
Now select Language Injection Settings and a window will open as shown below.
Uncheck the selected option and click Ok
Hope this helps somebody.
It happened to me when I removed the whole files in .gradle/caches, then studio downloaded the dependences. The dependences not showed in the External Libraries but I can build App successfully. rebuild clean Invalidate and Restart have no effect. I solved the problem by the steps:
Close Android Studio completely
Remove .idea package in your project
Restart Android Studio
I have tried this but nothing worked for me:
Invalidate Caches / Restart
Changing the order of dependencies
Sync project with Gradle Files
Clean -> Rebuild Project
In my case, just do:
Delete all files in .idea/libraries folder
Rebuild Project
For me I updated gradle-wrapper.properties into 4.4
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I found easiest way
Identify the library which is causing syntax error in Studio.
For Example if AppCompatActivity is showing error then you will perform below operation on AppCompat Dependency.
Remove dependency which is showing syntax error & Sync.
Add again & Sync.
That's It, error gone!
Before
After
None of the answers above works for me.
After a lots of attempts, I upgraded com.android.tools.build:gradle in Project/build.gradle from 2.3.0 to 3.0.1, and it works.
I guess the version of the com.android.tools.build:gradle should be match to the version of AndroidStudio, and my AS version is 3.2.1
I tried all of the posted solutions and none of them worked for me. (Though invalidate caches does normally. This time it made no difference). After trying everything posted here the "Error cannot resolve" were still present. And the project did build and run successfully, only the IDE seemed to be confused, not the actual app or device.
My Version of Android Studio is 2021.3.1:
The solution that did finally work for me was updating the "Android Gradle Plugin Version" configuration inside of File -> Project Structure.
It was originally 3.2.1 when it wasn't working. I updated it to 3.5.3 because I have another project that was working fine and it was on that setting.
After making this change and then sync'ing gradle the symbols not resolved error goes away and the IDE once again knows what those classes are.
Closing all files and closing Android Studio works for me.
You need to restart Android Studio.
I have a project in Android Studio which compiles with Gradle.
The general file structure is
MyProject
- MyProjectSource
- Libraries
- ActionBarSherlock
My project is built with Gradle and will compile without issue. However in the lines within my activity where I include a component from ActionBarSherlock, Android Studio marks it as an error.
I have noticed that Android Studio has also generated .iml files. So my question: Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?
Obviously this is not a project blocking problem but it does slow velocity not being able to take advantage of the full set of tools Android Studio has to offer.
Thanks in advance for any help.
These are not errors actually, this a bug in Android studio( 0.4.2 ) for resolving the symbol and fixed for the next release( 0.4.3 ).
To get Rid of these until the release do the following
Clean your project using Build > Clean Project
Close your Android Studio
Take Backup of your project
Delete all .iml files inside your project
Delete content of .idea directory
Open Studio and wait until it completes the sync with gradle
Also verify if you are seeing any error in File > Project Structure . If there is any error saying "Dependency Not Added "click on that and using red bulb on right side Add them to dependency.
UPDATE
Android Studio 0.4.3 is available on Canary Channel Now.
UPDATE: #laochiv, I have found that cleaning manually the folder .idea/libraries and clicking afterward on "Sync Project with Gradle Files" solves the problem. Apparently this Sync does not remove elements, but keep the old ones and add the current ones. Probably a bug to report :)
I am having the same problem. However, I am using ABS directly from Maven.
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
Even the ABS Gradle Sample application marks a syntax error, although it compiles.
However, in another computer everything is working perfectly. I can not think of different conditions in each scenario.
"Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?" Yes. Android Studio imports the project configuration but runs its own compiler as you are editing and saving (you can even change it to the Eclipse ECJ compiler). The true authority on the build is Gradle, and AS is still in beta. You can try to run the gradle resync or close and reimport the project. I have had to manipulate AS like this many times, especially after making edits to build.gradle.
Edit: I have found it better to use ActionBarSherlock as a gradle dependency rather than a library directory.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
You will need to use the SDK manager and install the local maven repository.
But it is possible to eventually get rid of these compile errors, as long as your build.gradle doesn't create any extra sourceSets that AS doesn't understand; try not to deviate too much from the android gradle plugin examples.
Also, I've been running the Canary updates of AS for the latest and greatest.
I don't know how to add a library using MavenCentral. I follow these steps to include a library
Add library in App_Name/App_Name/libs folder.
In App_Name/build.gradle add this
dependencies {
compile ---
compile files('libs/fileName.jar') }
./gradlew clean
Make sure your Android studio is updated.
Go through the link and it worked for me.
1.) Choose File option from menu on left top side of android studio.
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
3.) Click on the first button with option : "Invalidate and Restart"
4.) It will close the studio and restart it. Start indexing of the project.
It resolved my problem
Go to File -> Invalidate Cache/ Restart -> Invalidate and Restart
Source
https://www.youtube.com/watch?v=FX_gCTpqhwM
I had this problem in Android Studio 4.2, it might be fixed on 4.3
I have noticed that adding some dependencies did not attach the classes.jar to the dependency, so Gradle recognises everything but the IDE doesn't. To fix it:
Open Module Settings of your project
Select the dependency that has the error
Click Add (+) for that dependency (bottom of the pop up)
Navigate to your-project/build/exploded-bundles/your-dependency/classes.jar
The IDE should recognise the files now
Hope it helps
I had this today and gradle update/sync didn't solve. But updating to latest version of Android Studio 2.2 update 5 fixed (was on 2.1).
Here i'm talking about android studio version v3.1.2 where this same issue happened.In later android studio version(above 3.0.1) this issue again rises. So, I solved this by going through few things and here is how
Close android studio first
Navigate to your Project Folder
Delete .gradle and .idea folder (.gradle and .idea is hidden files. so make sure you tick Show Hidden Files in your File Explorer option to see these files
Open your project in android studio now
This Time another issue (unsupported module) will arise, but don't worry. I got you
Goto File in android studio and hit Sync Project with Gradle Files
Tada..! you're done now!
Simplest Solution
Comment/Remove the dependency which is showing syntax error & Sync Project.
Uncomment/Add again & Sync Project.
Yeah! error gone...
Before
After