package R does not exist after Refactor in Android Studio

Like many other, I like to use some projects as templates. And to make a template project the new project I want to create, I have to refactor the package name. But unfortunately, this process is still not working the whole way through in Android Studio. What happens is that the connection from every “R” call is still pointing to the “old” package name.

Normally you have a lot of Code like this in any project:

R.layout.fragment_list When you have this kind of problem, every Build and Run will fail with the Error:

package R does not exist

Here is the solution:
1. Go to Build and choose “Clean Project”
2. Go to Build and choose “Make Project or make Module”

3. Now, go through every Java file and look for red marked “R’s”

erro_R
4. In every Java file click once on <ALT> + <Enter> after the message shows up. This will refresh all the “R” – dependency to the new package name.

5. And finally, do again a “Clean Project” and the project is ready to be Build or Run.

 

 

Category: Uncategorized
Tags: