Android studio alway show "Gradle project sync in progress" - android

After update android studio Build number AI-141.1809159 version=1.2 in Canary update, i can't sync gradle project and always show "Gradle project sync in progress"

Following are the steps that I use (Kind a workaround),
Edit the root build.gradle file (adding a new line to file will also
do).
Save the file.
Restart the IDE (File->Invalid Cache/Restart->Just Restart).
Gradle Sync in progress notification should go away.

I found this was due to this plugin being used in AS:
'Android Studio Unit Test'
To disable this in AS 1.2 do the following:
File > Settings > Plugins > Android Studio Unit Test disable

Problem is solved, just update android sdk, it's work for me.

This happened to me twice and had to do with one of the gradle files having a date in the future (a glitch in Android Studio it seems). That is why just adding a space to the file and saving can fix the problem, as described above. Or go through your project with the operating system file explorer to find the file.

wait for some time, if you are using somebody else repo. It depends on the projects buildings. You might see new changes like file path, project-level dir appearing, etc.

Disable VPN if you have it active.

Related

Android Studio waiting for build to finish

I have a problem. When I start a new project in Android Studio and select a navigation drawer activity it happens. I don't have access to my activiy_main_drawer.xml on "Design" and it keeps saying "Waiting for build to finish.". I really don't know what I have to do. I tried to uninstall and reinstall Android Studio, and it didn't help.
I've just run into the exact same problem. I simply solved it by choosing Sync Project with Gradle Files. This will trigger a Gradle re-import and a build.
As of Android Studio v3.2, the icon is located near the top right tool bar. You can also find it using Find Action shortcut CtrlShiftA.
You can do the following:
"File > Sync Project with Gradle files" (worked for me)
File > Invalidate Cache & Restart > Just Restart
OR
File > Invalidate Cache & Restart > Invalidate & Restart
Close Project and Re-Import the Project
File -> Sync project with Gradle files
What worked for me was, from the top menu:
Build -> Clean
Build -> Rebuild Project
After that the xml design worked
Syncing gradle, reopening, rebuilding, invalidating caches and restarting, trying different Android studio versions. None of these helped. When I would open XML preview I would still see that damn issue.
What helped in the end is closing Android studio, going to gradle directory:
cd ~/.gradle/
And deleting caches folder:
rm -rf caches
After that reopening Android studio will take some time as it still has some rebuilding to do, but afterwards all xml layouts were being properly rendered again.
I am using Android Studio 3.1.3 (#AI-173.4819257), Android Build Plugin for Gradle 3.1.3 and Gradle 4.4. I tried all possible options mentioned on various posts but nothing worked for me. I want to use ConstraintLayout which is default with AS 3.1.3. My observation and workaround are as follows.
Observation: This issue occurs when a new project created with empty activity and default layout. I also get "IDE Error Occurred" once Gradle sync finishes.
Workaround: Create an empty activity, activity class (MainActivity.java) and layout (activity_main.xml). Once it is done, create a new layout file (say activity_cltest.xml) using New -> Android Resource File after clicking right button on "app". Create new layout as per your requirements. Once done, update MainActivity.java by replacing R.layout.activity_main with R.layout.activity_cltest.
I also tried to copy content of activity_cltest.xml to activity_main.xml but still for activity_main.xml, error persists. Effectively, once a new project is created, activity_main.xml should not be used and deleted.
However, for some reasons, syntax highlighting of "R.layout.activity_cltest" within MainActivity.java doesn't work.
Just create a new XML file using the same name and copy paste activiy_main_drawer.xml file codes. It works for me.
Have the save problem, the Android SDK was missing from my system.
After installation of this missing SDK, its running fine.
In my case it was because I specified recycler view's tools:listItem="<item_layout>" in body of <item_layout> (nested recyclerviews). Just removing this tools option solved it.
I uninstalled my 3.1.2 and installed version 3.2 Canary 18 from Android Studio download archives. Everything is fine now.
We welcome all constructive edits, but please make them substantial. Avoid trivial edits unless absolutely necessary.
Ah... I resolved it with the help on this page and a little bit more effort.
I installed Android Studio v.3.3.1 today on my Zenbook. I was stuck with the same error "waiting for a build to finish" and Display tab was not showing up for activity_main.xml
Here is what I did to resolve this error.
Step 1. I searched for SDK tools and downloaded required SDK versions.
Step 2. downloaded Gradle 5.2.1 and extracted the files in Program Files\Android\Android Studio\gradle
Step 3. File>Settings>Build..>Gradle and choose the local distribution of Gradle 5.2.1
Step 4. Go to File>Sync Project with Gradle files and allow some time to sync...
finish() :) developing android with Kotlin
My experience: I was accidentally importing "myself" into the view, creating infinite loop:
item_task.xml
<androidx.recyclerview.widget.RecyclerView
...
tools:itemCount="3"
tools:listitem="#layout/item_task" /> <---- circular dependency mistake
Setting a correct list item in the recycler view solved the issue.
I upgraded to AS 3.6 RC1 because of this time-waster but it still intermittently occurs!
Simply restarting AS has so far been working for me.
I've also faced this problem. The above solution wasn't worked for me.
I just restarted my Android Studio by closing the Android Studio application and opening it again from Start Menu. It works for me. Try this solution if the above not working. Hope this will helpful for you.
In my case, I was using an alpha version of material design lib, and it was not able to render any view in the project. Solved by downgrading to a stable version.
Stuck w/ the issue for a month, got it after AndroidX update.
Tried to invalidate caches, manually remove them (project, grade, studio), re-install studio, re-import project - nothing helped.
This script resolved it finally (w/ -nuke option)
https://github.com/rock3r/deep-clean
Sometimes while converting the code from java to kotlin some library may get imported like import android.R
Just remove this library.
Check this tools:context=".MainActivity" in xml while copying another XML the class name will also get copy.
Else try File -> Sync project with gradle or rebuild the project.

Android Studio - Android Project View is Missing

I've found some webpage but it does not guide me back to normal android project view.
http://developer.android.com/sdk/installing/studio-androidview.html
I did File => Other Settings => Default Project Structure => Default Settings => OK It make even worse, import library become not function-able.
I also had this problem (creating new project also looked similar to IntelliJ IDEA), got it fixed when I enabled some Android-related plugins.
Go to Preferences (Settings on Windows and Linux) > Plugins and enable Android Support, at a minimum.
Now you will have "Android" option in the Project View.
Try:
View -> Tool Windows -> Project OR the shortcut is alt+1.
If that's not working try:
Window -> Restore Default Layout OR the shortcut is shift+F12.
Also, check that Studio is up to date:
Help -> Check for update...
None of the above solutions worked for me so I fixed this by removing the .gradle and .idea folders from my project.
The square at the bottom left corner of android studio lets you spread the screen or it populates it with side menus.
For me, it happened when I used Kotlin KTS for Gradle files, but created a java library module for this project. After trying to reimport project I got an error:
New Gradle Sync is not supported due to containing buildSrc module
Solution:
Migrate added module to kts
Remove created by Wizard settings.gradle, if you already use settings.gradle.kts
Reimport project
File -> Close project
Android Studio: import project
Show it your current project location
Just had the problem happen to me again. I got the problem solved, but unfortunately I can't confirm the solution, now that it's fix; but I have strong suspicions on what was the cause.
In my case, the problem occurred as a result of reorganizing my project directory. My projects are stored in given directory lets call it "Projects". I renamed that fold to "ProjectsBackup" and created a new "Projects" directory. I then moved selected projects now contained in the "ProjectBackup" directory to the new "Projects" directory. After moving the first project, I used Android Studio to open that project. That's when the problem occurred. I got a message that it couldn't find the gradle-wrapper and offered me the choice to create it. The gradle-wrapper is stored in a directory call "gradle" and its stored in the "Projects" directory. I had not copied that directory over from the "ProjectsBackup" to the new "Projects" directory. At the time, I thought nothing about that since, a new one was created. After trying all the various suggestion in this problem discussion, android studio offered a notification from me to update my "android gradle" plugin. I did the update and after that the "android" view was now available for me to select. The android gradle update fixed the problem.
I unfortunately, can't tell you what changed as a result of the update, nor can I tell you how you can force Android Studio to update or reinstall the android gradle plugin. All I can tell you is that I got lucky that android studio gave me that notification to update the android gradle plugin. Things like "file/project structure" and changing the Android Gradle Plugin Version, didn't fix the problem. What I did notice, was that when I first looked at that, the drop-down list of android gradle versions was an empty list. I manually put one in "3.6.3", but it didn't help. If you run into this problems I would suggest you look at the dates of the two file in the "wrapper" directory and compare those to projects you may have that are working correctly with the android view. I wish I would have checked the date of the wrapper jar file, when it wasn't working. That's what I think might have been wrong (i.e. I got a wrapper.jar file that was incompatible with my version of android studio - unfortunately I can't prove that)
problem solve i have click this button

Why does Android Studio don't "accept" "getBoolean"? [duplicate]

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.

Android Studio says "cannot resolve symbol" but project compiles

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.

Android Studio Marks syntax as error, but gradle compiles

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

Categories

Resources