Cannot resolve symbol R and nothing is working? - java

So, I was working on a project in Android Studio, everything was going well until I had to sync my project and my R went red and now it doesn't recognize any of my layouts or anything of the sort...
I tried cleaning, rebuilding and Clean Caches - it's not working.

Try this:
first of all check your XML file where you are working now
maybe there is some problem in your XML file
after go to in your android studio and click file menu in dropdown select invalidate cache/restart

Try to below steps I hope it will help you.
Go to the projet and select option sync with gradle file's.
or once you have to try restart the android studio.

Related

after update android studio error not show and suggestion not appear in xml file

Before update android studio always show the error like if In linear layout declare the orientation. If write anything then show the error but after update android studio I have to write orientation="ygsdjgas" isn't show the error. Please look in the image
I want to show error like before update. Before updated android studio I have declare orientation="ahsgdah" then show the error but after update it not show the error and also no any suggestion like "horizontal and vertical"
Please confirm below highlighted options in android studio
If still doesn't work then first take backup of your project then delete .idea folder and all .iml files from the project, restarting Android Studio and rebuilding gradle did the trick. Intellisense (Autocomplete suggestion) in XML support library will work.
Checking out files from Version Control or copying all the source files in a new project would do the trick as well.
The problem has been solved. Only I went to the C drive and deleted the .androidstudio file and re-opened the Android studio and all got right for me.this is working for me

Android Studio not showing Inline Error

I am using Android Studio(3.0) to make an Android App. But suddenly the Android Studio has stopped showing inline errors where as there are still errors which are shown while building the app.
Till now I have tried the below solution
1) Clean Project
2) Rebuild project
3) Invalidate cache and restart
4) Check if the power save mode is on
5) Resync the Gradle
6) Delete the .gradle and .idea folder
But none of them have been useful. This problem has started suddenly.
Any help would be really appreciated.
Try running inspection manually with Inspect Code on the Analyze menu.
If that doesn't work then try doing this:
BACK UP your project.
Delete all .iml files and .idea folder.
Relaunch Android Studio and import your project
In my case, deactivate "Power save mode" solve the problem.
In menu "File->Power Save Mode" (just in the end of menu, preview to "Exit" option)
Slds!

Gradle Build Failed, :app:mergeDebugResources FAILED

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.

could not open initscript class cache for initialization script

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.

Java/Eclipse - No more R file ever

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.

Categories

Resources