In android studio, main activity, it says "cannot resolve symbol R". I have tried rebuilding and cleaning build. I have also updated buld.gradle to 2.1.3. The R is highlighted in red, and the path to the main activity is underlined in red. Thanks for the help.
Try this:
Go to File - Project Structure - Project and modify gradle version and Android Plugin version like the image
example
Clean Project and Rebuild
if the problem persists. Go to project path and execute
gradle clean build
Try This Method: Go To File->Invalidate Caches /Restart and Click Invalidate Caches and Restart
Image Here
If it Still Not Resolved Try Again and Clean Project and Rebuild.
Happy Coding..!!!
Have you updated your Android Studio as well? If that's not the case then try to update your android studio. Latest stable version is 2.1. If you have already updated it then problem might arose from the last activity or code you have written in your application. Such errors usually occurs when you try to manually update manifest or gradle or other build files. If that's the case then clean and build project will definitely solve the issue. These problems also arose after unexpected shutdown of IDE and internal IDE errors. If that's the case then android studio prompts you to report the issue to Google, you can do the same to seek further help.
Related
what is the actual root cause of this issue? I already sync with gradle files but eventually failed.
Just sync your project with gradles. File --> Sync Project with Gradle Files
Build -> Clean Project
Build -> Rebuild Project
File -> Sync project with gradle files . If not worked then try
File -> Invalidate Caches / Restart .
It's work for me !!!
That could be fixed in one or two steps, depending on how nice is Android Studio today:
Try to sync your project with gradle files:
If that doesn't work, invalidate Android Studio caches and restart. That should fix the problem:
The reason behind the first solution not working could be related on gradle cached dependencies problems, but who knows 🤷
This error mostly occurs when you're trying to open Android App from existing application and probably developed using different computer.
Almost all the troubleshoot methods like File->Sync Project, Build->Clean, etc. Might not work.
This is applied only if you are trying to open the Adroid Application from existing application.
The proper way to evoid errors is only to open sub folder from the path not the root folder. Below is the example of how to properly open the Android application from existing application.
For example in your Message_App/messages/msg path, you must open msg folder not your Message_App folder.
Message_App/messages/msg
>msg
>manifests
>java
>res
Just you have to do >> open File --> Sync Project with Gradle Files
and then after >> open File --> invalidate Android Studio caches / restart so done this problem.:)
sometimes Sync project with gradle File dosent work; you should check the compileSdkVersion in the "build.gradle" file , make them is the same number within all library/modlue
This issue is because the gradle file is not found when starting the project. To fix this ensure your connection to the internet is stable during project startup, the gradle file is downloaded automatically, after a successful download, You should be good!
Issue happened to me when I changed the res>values>styles.xml
What I change was
"Theme.AppCompat.Light.DarkActionBar" --->>> "Base.Theme.AppCompat.Light.DarkActionBar"
Solutions I tried.
Build -> Rebuild Project (Not worked)
Close all files and Open again. Then
Build -> Clean Project (Not worked)
File -> Sync project with gradle files (Not worked)
Close the Android Studio while project still opened. Opened it again. - It Worked.
If nothing of the above steps work, Then simply undo the changes that you have recently made, and then build gradle.
In my case, I have added one dependencies and this problem raised, so I removed that dependencies build the gradle and then again add it.
Problem Solved..!!
I had this problem and it was because I didn't have the right API level installed (and I was also getting an error to that effect). I went into Tools --> SDK Manager and installed the API the system was telling me I needed (in my case, 30). I did that and restarted Android Studio and was able to get into XML files.
I wanted to Setting up android studio, i have installed the latest version(3.1.0) of it and i downloaded and installed the latest version of gradle(4.6) and created a new object. but gradle project sync failed. and shown up the error :
Could not find builder.jar (com.android.tools.build:builder:3.1.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.1.0/builder-3.1.0.jar
screenshot
I Couldn't find such problem with the others.
is it related to android sdk or gradle version?
is there any solution to download it manually and place it in the
location??if it's possible , where is the location ,that i can put the
builder-3.1.0.jar file.
Go to File>Setting>Build,Execution,Deployment>Gradle>Android Studio>>
and
Check mark this:: Enable Embedded repository
and Click Ok.
Then,
Rebuild the Project.
or
go to Terminal and type "gradlew cleanBuildCache" to clear the cache. The cache is in USERNAME.ANDROID\BUILD CACHE Directory.
And Rebuild.
Try deleting ~/.gradle folder and building the project again. Gradle will download that.
Accepted answer did not work for me, so I changed the class path line in gradle (project : project name) and issue is gone.
classpath 'com.android.tools.build:gradle:3.1.2'
I have tried all of the suggestions and none of them worked!
if you are facing the same issue i suggest you to do what solved my problem , i have found out the problem may caused because:
most likely at one time this dependency version was available, and so it’s now available on your Mac/PC in the filesystem (cache), and Gradle won’t try to download it (as it’s already downloaded). But then the version was removed / is no longer available, so it will no longer work on any new Mac/PC (as the dependency version can’t be downloaded).
hopefully if you have a backup before this problem happen these steps might help you to fix this issue
1) Backup or push the file you have changed to git (I suggest just your code files not anything related to gradles or android files)
2) delete C:\Users\ (your User)\ .gradle\caches
3) Do a clean git clone of the repository, into a new directory
4) Open new copy of your project with Android Studio and let Android studio sync gradles again
Check the version of Android Studio you are using...i was Android Studio 3.1 when it gave me the problem....i downgraded my Android Studio version to 3.0.1 and the problem solved.
I battled with the same problem for a very long time. But I was able to resolve it. You can try this:
Go FIle > Settings > Build, Execution, Deployment> Build Tools > Gradle then check the option Offline Work . You will notice that it points to a local gradle directory on your computer i.e C:Users/User_name/.gradle. Click Apply then OK. Run your project again, it should work.
Below is a screenshot:Screenshot of the Fix
go to SDK manager and download other SDK platform
I am trying to import this project, even I tried to import other few projects too, I am getting below error.
https://github.com/ashdavies/data-binding
I have spent my 5 hours on it, even I tried many solutions on google but nothing gonna worked for me.
I tried following solutions, nothing worked.
1) delete .gradle directory
2) Restart IDE,
3) I tested with com.android.tools.build:gradle-experimental:0.7.0-alpha1
I am frustrated because of this Gradle and these issues.
Gradle Version : Gradle-2.13, I do not want to change this version.
Android Studio Version : Stable 2.1.1
Note : My other project is working fine and I can build it too.
You can try different workarounds for this problem :
1- Clean project and Rebuild it.
2- Before importing the project, remove the contents of the Build folders.
Then replace the contents of your gradle-wrapper.properties file with the following lines, to make it use a local distribution for building the project :
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=file\:/opt/gradle/gradle-2.13-all.zip
in which, the last line prevents android studio to download or use a corrupted gradle cache.
Go to any browser
type gradle and press enter
you can specify any version you want after the
gradle keyword
i am downloading gradle 3.3
https://services.gradle.org/distributions
click on this link which is in description directly if you want
click on gradle 3.3 all.zip
wait for the download to complete
once the download is complete
extract the file to the location
c://user/your pc name /.gradle/wrapper/dists
wait till extraction it takes 5 mins to complete
Now open your project in android studio
9.go to file > settings >bulid ,exec,deployment > gradle
now change use default gradle to
use local gradle distributn
select the location where you had extracted gradle 3.3.zip
C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3
click on OK
Now build starts again and
you can see now the build is successful and error is resolved
or
watch tutorial
https://www.youtube.com/watch?v=u92_73vfA8M
In my case, it was happening because i haven’t set the JDK path in environment variable.
Please check from your Android studio studio that your JDK path is correct.
Go to Project Structure> SDK Location and check JDK Path. Give it the correct JDK path and also set the JAVA_HOME environment variable.
You can try this solution as i was facing this issue showing Error2 Gradle's dependency cache may be corrupt and gradle build not working and resolved it. Already answered this question on stack. You can reffer to this answer link
It includes firstly downloading latest graddle version from official site then replacing that unzipped file with home/yourUser/.graddle/wrapper/dists containg older version file on Mac.
Because your gradle path for project is incorrect.
Go to
->Settings
->Gradle
and select "use default gradle settings"
and than sync project. and issue will be resolved.
delete .gradle, .idea and gradle folder from the project and then invalidate cache and restart.
problem will be resolved.
Thanks :)
Sometimes it's a cache issue and sometimes due to interruption in download.
Step 1:
Try to download gradle distribution manually
https://services.gradle.org/distributions/
and then go to project settings -> gradle -> and use the file which you've downloaded
Step 2:
If step#1 still not working, then it may be a cache issue. If you are a mac user, go to your finder user folder, show hidden items by pressing [Command + Shift + .] , Go to gradle folder and
In my case is that gradle-5.1.1-all.zip download failed, so I go to zipStoreBase+zipStorePath(configured in gradle-wrapper.properties, eg: E:\gradle-home\wrapper\dists), and delete the gradle-5.1.1-all directory, and let android studio to download that zip file again.
Error:Could not open initscript class cache for initialization script 'C:\Users\Avishek\AppData\Local\Temp\asLocalRepo14.gradle' (C:\Users\Avishek.gradle\caches\2.2.1\scripts\asLocalRepo14_dkwbdtenxxgt2q2wfe57wj30b\InitScript\initscript).
java.io.FileNotFoundException: C:\Users\Avishek.gradle\caches\2.2.1\scripts\asLocalRepo14_dkwbdtenxxgt2q2wfe57wj30b\InitScript\initscript\cache.properties (The system cannot find the file specified)
This error gives when I want to rebuild a project or clean project or run project.
Please someone help me...Thank you...
Don't use Gradle with a fresh version of JDK. It may not support it. In my case, downgrading JDK solved the issue.
You should delete "scripts" folder from "C:\Users\user.gradle\caches\2.4\" via this answer. Then refresh gradle from Android Studio. This worked for me.
You may have opened Android Studio twice. In that case close one of the instances and click on Try Again or Synchronize Gradle, or restart Android Studio. It is because the gradle build was not completed and other dependencies like classpath did not initialize at startup.
You should check android studio power save menu in file. If it was previously selected, then it should be unselected the power save mode in android studio in file menu. I hope it will be worked.
In my case I have deleted .gradle folder and clean the project on re run the project was working fine.
Close the android studio
Delete this file from your pc C:\Users\Avishek\AppData\Local\Temp\asLocalRepo14.gradle
Delete folder from your pc C:\Users\Avishek.gradle\caches\2.2.1
Your app in .gradle and .idea file is also delete
And start your android studio
2022 New Answer for Kotlin base projects
Open IntelliJ IDEA CE
Click Create New Project or File/New/Project
Important !!!
Select Kotlin from left side of window.
Select IntelliJ in Build System.
Click Next.
Done. You will not have this error when you run your Kotlin file in the IDE.
I'm on Eclipse for hours now and I didn't found a solution yet for my problem even after many searches on internet: I have no more R.java file on my projects.
On just created or on my old projects, i don't have R file anymore and I tried so many solutions (uninstall, re-install Eclipse, clean my project, check all my XMLs, fix problem with android tool and so on ...)
Please someone can tell me what to do in this case?
Hey If you just updated to ADT Rev 22 :
I had the problem too. There is a new component in the Tools folder called "Android SDK Build-tools" that needs to be installed.
Step 1
Open the Android SDK Manager
Step 2
Select the newly added Build Tools and install. (If problem stays then go to Project Properties => Java Build Path => Order and Export and check Android Private Libraries, then clean and build project.
It may be necessary to repeat the process, restart the SDK Manager after the update and make sure it looks like this (all tools installed):
More info:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/rCaeT3qckoE%5B1-25-false%5D
Perhaps in Project Properties -> Java Build Path -> Libraries you don't have:
Android 4.2.2 (or other version)
Android Dependencies ?
If so, then right click project - > Android tools -> fix android properties
and see if this library showed up.
Thank you all for saving me! I've spent the whole afternoon on search this error.
Finally, my project works.
By the way, I also encountered one problem which i wanna share with you:
After upgrading, even if my project has not errors anymore. During runtime, it seems it couldn't find the classes from the jars placed in \libs.
Go into Project=>properties => Java build path= > Order and Export.
Please make sure all your jars are checked.
If this problem occurs suddenly in a well working project,
the first step is to find whether the problem occurs only in the current project or in all other projects.
if all other projects in the current workspace are working then 90% problem is with XML / mainfestfile/resourse file that you edited recently.
This error is not shown as red mark we have to find out what we have done recently in these files.
try this
sudo apt-get install lib32stdc++6 lib32z1 lib32z1-dev
it solved my problem
Close your eclipse and after refreshing system, try to open Eclipse again. I think you are using Emulator along with the eclipse. It may be because of the low Memory problem (RAM) of your system. I used to face the same problem when I use Emulator
whenever there is any mistakes in any of the xmls the R goes missing when a build or clean happens so check for any xml errors in your project unless you fix it you cant get back your R on clean or build. fix the xml files and perform a clean you will have the R generated. Also check in File->properties->Builders and see if everything is checked
I was using Eclipse Indigo and nothing I tried worked. I ended up downloading Juno SR2, reinstalling the ADT, and now everything works again.
Reinstall everything and it'll work.. i.e. go back to Google SDK or w.e. you're using and download it.
Update it to latest in SDK Manager.
Go into Eclipse-Project-Prefs-Java build path-order/export TICK EVERYTHING.
problem: No R file get generated.
guess: Try cleaning project if it is old one. Else create new project with no R get generated and with no compile errors but this: no project.apk
In this case you have to check your SDK for the built-tools. May not be installed after updating SDK.
Thus download them if not download here, then put them under directory: SDK/built-tools folder. Lastly, and most important, is to Run the SDK As Administrator. This guarantees refreshing SDK with all packages appearing in it.
Install the SDK-Built-Tools or any missing packages according to the above link and you're done.
hope this helps.
Try one thing, create a new Android Project and transfer all those files which are in the previous project. That worked for me.
In my case there is error due to "&" inside strings.xml file(but error not shown) for declaring string for a array type. Now the problem has been solved as I changed "&" to "and".
So, please make sure that you do not have such silly use of symbols, and clean the project.
I have had the same kind of problem, however Rechecking all XML files in the Resources folder was helpful in my case. I found syntax error in my XML files. Cleaning and building the project again can be helpful sometimes too.
I had the dreaded not more R.java.
Some of the things I've used in the past:
Clean / rebuild (the first thing we all try)
Restart eclipse (optionally reboot pc/mac)
Update both SDK/ADT eclipse plugin to latest version
Create new eclipse workspace and import project
Enable Verbose AAPT build output Eclipse menu>Preferences>Android>Build
Port project to Android Studio / Gradle (this helped my actually see the AAPT error i was getting Error Code:138)
Delete recent XML changes - Ultimately I found deleting recent menu.xml files I'd added and commenting out where they were referenced fixed the issue and I finally got R.java.
I got the error recently and had found no fault in any layout or value file. After a lot of tries I add another Activity and the R.java was build and the error disappeared. I don't know why this occur, but it takes me hours.