like I said: I accidentally deleted include ':app' and i clicked sync.
Now i rewrote that line again, there is no sync button so for me: everything is lost.
Do i have to start a new project to soleve this problem?
Thanks in advance.
There is no Tools -> Android -> Sync Project with Gradle Files and Build -> Rebuild Project
Closing project and importing project fixed the issue. None of the solutions above worked by the way
Close and Re-open the build.gradle.
Add back the line you deleted.
If the Sync button still does not show, go to the next step. If it shows, just sync.
Change something randomly in dependencies, build types or default config.
Once the sync button shows, revert back the random change.
Press Sync.
Also try File > Invalidate Cache 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 just added the google-play-services-lib library to my project and am stuck where I need to "sync the project with gradle files", but this button does not exist on IntelliJ 13.0.1. Is there an alternative to this function?
As alternative you can use Refresh all Gradle projects button in Gradle tool window.
I also have not found this button so I made my own :)
Open Gradle tool window with View -> Tool Windows -> Gradle
Start Macro Recording with Edit -> Macros -> Start Recording Macro
In Gradle tool window press Refresh all Gradle projects button
Stop Macro Recording with Edit -> Macros -> Stop Recording Macro
Save Macro with name Gradle sync
Press with right mouse button on IntelliJ IDEA toolbar and choose Customize Menus and Toolbars...
Under Main menu -> Edit -> Macros -> Macro Actions find your Gradle sync Macro, select it and press Edit Action Icon...
Download this icon Sync Project With Gradle Files icon (from documentation http://developer.android.com/google/play-services/setup.html) and select this icon in IDEA dialog window
Now in Menus and Toolbars select last item in Main Toolbar group, press Add After... and select All actions -> Macros -> Gradle sync
Now you have Sync Project with Gradle Files button!
There is a useful shortcut Ctrl + Shift + A, after which a window appears and you can type some command that you would like IntelliJ to run. Just type "sync" in there and it will find that command Sync Project with Gradle Files, even if it's not visible in the menu.
"Sync Project with Gradle Files" is not present in IntelliJ. However a similar option is available to build all the gradle files together. Go to View --> Tool Windows --> Gradle. A Gradle task panel gets displayed in the right side with the list of apps. Select your app and click the "Refresh all Gradle projects" in the top bar of the Gradle task panel.
Another method is as mentioned by "Avi Arro"
The Gradle sync is still there, under Tools -> Android -> Sync with Gradle
If you don't see it, then Intellij needs to re-link your gradle file.
Try closing the project, re-opening by File -> Import Project -> and select your .gradle file
In my Case, One of My plugin, Android support got disabled due to some reason , As soon as I enabled it , and sync it the button automatically showed.
Go to File > Settings > Plugin > Android support(Tick this).
and sync your project.
I haven`t seen such option in pure IntelliJ. I guess you are developing some android app. You should then switch to Android Studio (based on IntelliJ) where this option is available for sure.
http://developer.android.com/sdk/installing/studio.html
Just in case someone who uses Android studio is experiencing this issue (can't find sync gradle feature), I'm posting my answer here. I'm new to Android, so I had no idea to fix this. What I did was I cleared the AS cache.
File > Invalidate Caches / Restart
Voila! The Gradle sync button is now there.
I try to import an eclipse project into Android studio.
In the migration instructions it says "In the following dialog, leave Use gradle wrapper selected and click OK. (You do not need to specify the Gradle home.)"
The problem is that the ""Use gradle wrapper" is unselected and grayed out.
Any suggestions?
1) Create a new simple project with Android Studio.
2) Find the gradle folder in the new project.
3) Use the export option in eclipse to create the build.gradle script. (Requires at least adt version 22.0)
4) Copy the gradle folder into the project you want to export to Android Studio.
5) Now try to import this project, u shall be able to select the wrapper check box.
This may resolve the problem you asked for, you can also set the Gradle home path and use the other option just fine.
Hope this helps!
I had this issue with a project that I had already previously built using Android Studio. It turned out that selecting the project appended a /gradle to the path of the directory when searching for a gradle wrapper. Removing the /gradle allowed me to select the option to use the default gradle wrapper.
For those intellij + Gradle users, that arrive here via Google...
I had the same "greyed out" issue, on osx, NOT on an Android project though.
To resolve, I had to...
Install gradle. (If not already installed)
(if you use Homebrew)
`> brew install gradle `
In the terminal, remove your gradle/wrapper folder.
Run the gradle wrapper task (this will download/create the wrapper)
> gradle wrapper
Attempt to re-import the project in intellij
I had an existing project with this problem. I already had gradle on my system, so what I did to fix it was remove everything from my build.gradle except:
task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}
If you don't have a build.gradle, create one. Then run gradle wrapper. This will download the wrapper. Then put the original (Android-ish) contents of your build.gradle back, and go to your Project Settings in IntelliJ/ADT. You should be able to choose the Use gradle wrapper option now
Here's the simpliest sollution which works for both AndroidStudion and Intellij Idea
Go to Preferences -> Build, Execution.. -> Build Tools -> Gradle
Check "Use gradle wrapper task configuration"
Click apply (gradle wrapper will be downloaded, gradlew, gradle.bat files will be added to your project)
Check "Use default gradle wraper"
I had this issue and the only way I found to fix it was by deleting my Eclipse and SDK directories, deleting the settings/preferences, as well as my Android Studio settings/preferences. It isn't the most elegant solution, but I was able to get it to work by doing this.
My suspicion is that something wasn't happening right during Export, because it was the last variable I changed after already attempting a reinstall of Android Studio.
As someone else said, you need to first create a new project with android studio, and use the gradle file found in that project and paste it into the project which you want to import.
how can I sync changes I made in the build.gradle into the project structure ( e.g. that AndroidStudio is recognizing the lib I added?
Kind of like the "reimport all maven projects" for maven projects - just for a pure gradle project.
I read somewhere that the "Synchronize" item on the module's context menu should update the IDE's settings based on the build.gradle file.
Ok, so in the latest version of Android Studio 0.1.3, they've added a Gradle project refresh button next to the other Android specific buttons in the toolbar. Make changes manually to the build.gradle files and settings.gradle and then click this button. It should configure and refresh your project settings based on the gradle files.
One thing that has worked for me was opening the Gradle panel on the right side of the editor (above "Maven Projects" and "Commander") and clicking the refresh button. That refreshed the module settings.
For Android Studio 4.1.2 click on the button pointed on picture
My solution for newer version of Android Studio. Tested on version 3.2.1. You can selected Refresh from the menu as showing here: