I am making an Android app. Due to some reasons, my current project files got all messed up. To solve this issue I created a new project in Android Studio and copied the files from the previous project to this new project.
I carefully copied all the layout, values, java files at their right location. I replaced the relavant content from the new manifest and gradle files with new content.
Everything looked perfect and then I got the "Cannot resolve symbol R" error.
I tried all the solutions like Invalidate Cache/Restart, Sync files with gradle, Rebuild Project, Clean Project etc. etc. etc.
Still couldn't fix it.
Can someone help?
Problem Details 1. I have correct package name everywhere (in AndroidManifest too) 2. I have proper and valid xml files 3. Even if I copied the files from other project the I've kept the project name and package names exactly the same. 4. I have only one app module.
尝试从每个 java 类中删除 .R 行。
You might have an error in one of your xml
files, like a duplicated xml
header. Check for every single one.
You can also update Android Studio as it now tells you the file and location of the error.
I strongly suggest you copy and paste your codes to individual right places if you want to move these to a new project. Copying folders and files to a newly created project would not work as there could be some lines that include your old folder paths
For example, your old project was in C://StudioProjects/YourProjectName
so your codes should be in C://StudioProjects/YourProjectName/app/src/main/java/com/example/AppName
but if you directly copy a file or folder to a newly created project, you could end up referencing the wrong path like C://StudioProjects/YourProjectName/app/src/main/java/com/example/NewAppName
and this could blow your XML file which will lead to R cannot resolve symbol R.
Even though you put your folders in the same path, reference numbers changed in the new project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.