Android Studio R Build File
I am working on an Android application that has worked and tested many times. However, today, while trying to run the application for further testing, I encountered the following error message:
C:\Users\1000\AndroidStudioProjects\WarofSol\app\build\generated\source\r\debug\com\blacktentdigital\warofsol\R.java
Error:(1251, 32) error: identifier expected
Error:(1251, 34) error: illegal start of type
Error:(1251, 35) error: identifier expected
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
>Information:BUILD FAILED
The problem is in the file R.java
(as stated above). This is a generated file, so I never touched it.
The line of insult is as follows:
public static final class drawable {
public static final int 3=0x7f020000;
Hover over the offending line: "Identifier expected | Unexpected token"
Comparison with other R files shows that "3" shouldn't be 3 and is obviously corrupted.
Attempts to replace a line or file with older fallback versions have not yielded any results because (apparently) every time I try to build the assembly, the file is not regenerating correctly, and I don't know what can do that. As I said, the problem arose suddenly without any provocation that I know of.
I have also tried closing the program and restarting my computer to no avail.
Any ideas as to what might be causing this and how it can be fixed?
source to share
I got the same error when I defined a line in the xml file like this.
<string name="3">Settings</string>
Mistake:
Error:(1426, 32) error: <identifier> expected
Error:(1426, 34) error: illegal start of type
Error:(1426, 35) error: <identifier> expected
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Solution: Resource name must begin with character
. So I just changed the String like <string name="S3">Settings</string>
and it worked.
So, just check if you have 3 resource name in all resource files (string.xml, style.xml, attrs.xml) and folder (pull, layout).
source to share
This is a quote from the java documentation:
A variable name can be any legal identifier — an infinite sequence of Unicode letters and numbers, starting with a letter, the dollar sign "$", or the underscore character "_".
And you called the drawable with a digit which caused the problem.
source to share