How to remove "cannot resolve symbol" for already added dependencies - android

I am receiving a "can not find symbol" error for dependencies which are already added to the project
The app is running on android studio 3.1, and it compiles and runs normally, as if there are no dependency issues. I tried clearing gradle cache with the cleanBuildCache command, and I also invalidate the cache from File > Invalidate Cache/Restart but to no avail.
Import error in red
Support libraries under dependency on the right, but not showing in external
libs on the left

Try doing the following:
Save your project and close Android Studio
DELETE Project Name.iml file from you project directory
DELETE app.iml file from your Project Name/app directory
DELETE .idea folder from your project directory
Project Name is the name of the project that you set when you first created your project in Android Studio.
Relaunch Android Studio, load your project ,sync gradle and build again.
NOTE: You might have to be connected to internet as it will download the libraries again that were delete when deleting the .idea folder
Also update your gradle verions and use implementation instead of compile as it was deprecated long ago.

Have you tried Build > Clean Project? Or a good old fashioned restart of Android Studio?

Related

Migrate project to gradle file??This project does not use Gradle build system.We recommend that you migrate to using Gradle build system

Am not getting gradle file in the Android project as it is unavailable in android studio bt is available in project file folder. I tried a lot to resolve this issue but I failed.
Thanks in Advance
The project thinks it's still a non-Gradle based project; it's not the presence of the build.gradle file that makes it Gradle-based, but it's how the project was set up in the first place. You'll need to re-import your project to finish the conversion to Gradle.
First, though, it looks like you don't have a settings.gradle file; it looks like you need one. Since you've set up your project as a single-module project, then you can put the file in your project's root directory, next to build.gradle. It should contain this:
import ':'
In the future if you add more modules to your project you may want to convert it to a multi-module directory structure, but you don't need to worry about that now. In any event, now you need to do the re-import in Android Studio:
Close your project
Back up your project
Delete the .idea folder in the root directory of the project
Delete all the .iml files in your project
Import your project in Android Studio, and in the dialog that prompts you for a file, choose the build.gradle file.
After this, you should be good to go.
I have facing an exact same situation in past, I solved this error by following step
First of all I would remove following files/directories from your project-folder:
bin/
build/
.idea/
.gradle/
projectname.iml
when you open android studio import your project

Android Studio, Junit cannot be resolved even after Junit4 added to classpath

How it happened
the unit test class works fine initially.
I encountered this issue after removing the C:\users\my_username\.Android\.gradle folder, and redirecting gradle dir in Android Studio to E:\Android_file_folder\gradle.
Since then, my unit tests cannot be compiled any more, although I have tried the following,
Disabled work offline option
Adding implementation 'junit:junit:4.12' to classpath
In Android Studio, File -> Invalidate Caches/Restart
Clean project and rebuild project
Problem Symptoms,
annotation in unit tests (#Test, #Before, #After) is red. When pressing Alt+Enter over these annotaion, the pop up menu keeps giving me the option to add Junit4 to classpath.
I check the gradle folder ( E:\Android_file_folder\gradle\caches\transforms-1\files-1.1\junit-4.12.jar\2509a789951ff3e52dd4785783415e3f ") it is empty.
Can you show me any additional steps I can try to resolve this issue?
This issue is resolved by doing the following,
deleting the .gradle directory in the project directory.
deleting the .idea\libraries
sync gradle
It appeared that despite changing the service directory under File>Settings>Build,Execution,Deployment>Gradle>Service Directory Path alone without deleting the mentioned folders doesn't stop the project from looking in the old directory.

Android studio: this project is not gradle based project

I have one project which was initially in eclipse, then i managed somehow to convert it to gradle and everything was working fine in Android Studio.
But then i didn't work some time with the project and after few months when i returned to project i am surprised that Android Studio has problems with this project.
When i selected "Android" from top left dropdown in AS, where you should see the project as Android, i saw no files, then i did something and now i see there one empty folder Java.
If i hit button "sync project with gradle files" AS says message as posted in name of question, but it is gradle based project.. there are gradle files etc.
Do you someone know why is this problem? Why it should stop work like this?
Thank you
Make sure you open the project from its root directory. i.e. the directory which contains the top level build.gradle file.
The missing top level gradle file is what causes this error.
For native Flutter Projects:
Note that this error will also appear if you "sync your project with Gradle files " in the root directory. Gradle works only in your android directory (flutter_name/android).
Configure Gradle version
I got this error because i wanted to change some build values like the Gradle version and the Gradle plugin version (and other build values ex. kotlin):
In your current project: File>Open
Select directory: user/StudioProjects/flutter_name/android
Open directory in a new window
After it is opened it will load some packages (see right bottom), which will take some time.
Under File>Project Structure Project you can set the gradle version and under Modules variables of your build
Now you can sync your project with Gradle files or at least read out the error messages, that come with your configuration
After configuration, you might need to restart your project with File>Invalid Caches/Restart....
That worked for me:
copy the file build.gradle
drop the copied file build.gradle in
your app/project folder .
My project stopped showing all of sudden and already had build.gradle file.
I just reopened it via File > Open.

Vuforia-Samples in Android Studio Error

I load the Vuforia project into Android Studio and get this Error-Message:
Migrate Project to Gradle?
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
+
Error running build: Cannot find script C:\Users...\vuforia\v2\samples\app\build.gradle
Actually the build.gradle file is in this folder.
I followed these Steps:
Close your project
Back up your project
Delete the .idea folder in the root directory of the project
Delete all the .iml files in your project
Import your project in Android Studio, and in the dialog that prompts you for a file, choose the build.gradle file.
,but not successfully.
Sorry for my bad english.

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