Illegal underscore in R.java - android

After updating to Android Studio 1.3.2, I've got strange mistake
Error:(2056, 77) error: illegal underscore in R.java (more details on the screenshot below)
But name 11880432_466668553495145_5076754104009227271_n was not found in project at all anywhere, except R.java. Also, this color was found in android support, design support libraries and android support cardview, but it has normal names there
UPD
There was a problem with encoding in file name in drawable resource directory. Problem solved

It's a bug, I solved this problem doing
Build > Clean Project or Build > Rebuild Project
If it didn't solve your problem make sure that in your Drawable folder are not a Drawable with a name without uppercase and symbols like (#,#,$) etc.

Related

Android studio randomly messes up gradle formatting?

I will be editing a completely different file than the gradle file... then out of no-where all my objects won't be referencing their proper packages.
The gradle file's format gets messed up then throws this error:
Error:(57, 0) Could not find property 'provided' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#4bd72df3.
Open
File
Running: Android Studio 2.1
This might be happening because of different package names defined. Packages in your project structure and the project ID defined in the gradle file might be different. This difference creates a problem during gradle build. Please paste your gradle file and also a screenshot of your directory structure.

'Cannot resolve symbol' and 'No resource found that matches the given name' - not a duplicate

I opened my project in Android Studio yesterday and got red everywhere with 'Cannot resolve symbol' as the description. It was completely random as no changes had been made to either the project or AS since the last time I opened the project. I ended up updating Android Studio to 2.0 and trying a bunch of solutions I found online but nothing works.
Like this guy, I have already tried:
Rebuilding the project
Cleaning the project
Syncing with Gradle Files
Closing the Project, closing AS and relaunching / reopening
File > Invalidate Caches / Restart
Examining Lint, didn't see anything obvious
Double checking all support libraries are up to date in the SDK manager
Examining my Build.gradle, although no changes and it's the same as usual, the way it was working all the time.
I have also tried the following steps (from the accepted answer):
Exiting Android Studio
Backing up ymyour project
Deleting all the .iml files and the .idea folder
Relaunching Android Studio and reimporting project
I also tried:
Removing the 'proguard' entry in build.gradle
Changing to "Use default gradle wrapper" in preferences
Another solution is to move 'buildTypes' in build.gradle but 'buildTypes' is already at the bottom of the Android section
Don't mark this as a duplicate if the "duplicate" is someone who fixed the same problem by doing something that didn't fix my problem.
Here are some screenshots:
As you can see, the color 'white' does exist:
R errors everywhere as well:
These errors are everywhere too:
Why are there two res directories and why is the one with the necessary resources a sub-directory of the java directory? Could this be related? Screenshot here:
EDIT: I created a drawable directory in the main res directory and added one of the drawables that won't get picked up by build variants. It removed the relevant 'Cannot resolve symbol' error. But when I deleted the main res and tried try to move the whole res directory in the java subdirectory to the main directory I got the following error:
EDIT: I managed to build without errors by deleting the outer res directory, copying the one inside the java one, pasting that into the main directory then deleting the one inside the java directory. How these got moved around like that I do not know. Probably caused by following the 'solution' of deleting and importing the project again. Whether it actually runs properly on a device I do not know as Android Studio is hanging for the last 20-30 minutes (as it does sometimes). If it does I may answer my own question with what I did to finally fix the problem.
The error shows you that you do not have value white in color constants.
Please check all your resource files (colors.xml, strings.xml and so on) - do you have line
<color name="white">#FFFFFF</color> in one of them?
Try creating a new project entirely, and copy and paste everything. XML files, classes, etc. That should solve your problem.
Eventually solved it by moving (by copying, pasting and deleting since AS wouldn't let me move it) a res directory that had been misplaced from deleting and re-importing the project to try and fix it initially. I don't know which one of the solutions worked but one of them must have. I just had to fix my project again after the re-importing 'solution' broke it. The res directory was a sub-directory of java when it should have been one level up as a sub-directory of main.

Error Building Project in Android Studio "Error: No resource found that matches the given name (at ____ with value '#drawable/<name>')

I've searched all over Google, stackoverflow and other android programming websites, many have suggestions for people who have misplaced files from one folder to another and so forth.. But none that illustrate the problem I'm facing.
It's not a corrupt file as in the case here as I tried this with no success.
The error I'm facing is similar though:
[debug] C:\Users\Name\AppData\Local\Temp\android_manifest_copy6264790980678653632tmp\AndroidManifest.xml:11: error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_launcher').
Similarly, this is happening with an #string element, #style element and another #string, examples below:
'#string/app_name'
'#style/AppTheme'
'#string/app_name'
One thing that I have noticed, and coming from the world of Eclipse, I cannot explain this behavior in Android Studio.. In my 'main' project folder, everything exists and builds correctly for debugging. It seems that Android Studio is trying to build off of a 'debug' folder, which will not build when running 'Build' > 'Rebuild Project'.
Does anyone know where I can place these missing files to get the project to build? Or is this some other problem?
Alright, so after fussing with the rebuild for hours trying different methods (renaming particular files [i.e. those with the problems], rebuilding the app after renaming folders inside the build folder, etc) I finally decided that I would go to the source of the problem and see if it worked like other IDE's. Indeed it did, this is how I performed the fix:
Find the location of the problem - For me, all four of the errors I had were inside the 'build' folder of the project.
Close any open instances of the project
While the project is closed, rename this folder from windows explorer (or other if youre using a different OS) (i.e. If the folders name is "build", rename it to "build.old")
Open the project once more
Go to Build > Rebuild Project
You should not have any issues doing this, like I did.
Specifications:
IDE Platform: Android Studio
IDE Version: Android Studio (I/O Preview) 0.2.2
JRE: 1.7.0_25
My problem is about #drawable/img_1, the pic is JPEG format, while it's extension name is png, I force to rename it jpg extension. Then it builds successfully.
If anyone is using Gradle and sees this it's good to remind about the convention directory structure.
For Gradle you have to put your resources in src/main/res. I migrated a project to Gradle and got the said error when I hadn't moved the res/ directory from the old structure.

Missing myProject.R file in android

It seams that I missing the R file, this is a common error and usually I have solved by cleaning the projects, using android tools fix project properties and restarting eclipse.
Now I have installed the new android developer tools eclipse and after importing the project I have this error in eclipse:
Errors occurred during the build.
Errors running builder 'Android Pre Compiler' on project 'MyProject'.
java.lang.NullPointerException
and the R file is not generated so it is missing.
The project is a library project. Thanks
Sometimes if you have errors in an XML file, it will stop the project from building correctly and the resources (project.R) file won't be created properly. You will also need to make sure that you are importing your resource file and not the one from android.R
If you've changed the project build target or minSdkVersion, you might have XML nodes in one of your layout files that isn't supported by the SDK you are using which will stop it from building. That's also worth checking
Go to Project and hit Clean. This should regenerate your R.java file.
Also get rid of any import android.R.* statements and then do the clean up as mentioned.
Otherwise, XML resource under layout may not having the correct naming convention or might be having some capital letters.
Try changing them to lowercase and make sure your layout.xml files don't contains errors.
Clean the project because the project may have trouble finding the name of a resources, it really sucks that i constantly have this problem when adding new image..

Android R Cannot be resolved issue

I have just been working on my android project in eclipse and all of a sudden this error appeared, my manifest file matches the name of my application etc.............!
What I have noticed is that that the auto generated Java files are missing from the gen folder its completely empty now.
orginally I had to create a default.properties file as there wasn't one present and it was working fine uptil the point i tried to add a button into one of my xml files. Tried to clean project too and that hasn't resolved the issue either.
Any ideas?
This error is usually caused because you have an error in one of your resources. Check to make sure that there are no errors in the xml resource files or the drawable directories. In the list of errors you are seeing you should look at the top most error and see if you can resolve this. What tends to happen is that an error in one of your resource files is causing the generation of the R file to fail. Once the R file fails to generate you will see a huge list of errors but they are all caused by the one error.
Remove the gen folder from Project Name ->Properties -> Java Build Path ->Source. You will get an error message after removing it. Now Add the gen folder again in the same way. You can now see the R class. If the problem remain, then try to remove both src and gen; add them again.
use "Project" -> "Clean" in Eclipse to re-generate your R file and fix other android issues.
...sometimes this helps a lot! ;D

Categories

Resources