Renaming the package that R.java is generated in
Solution 1
Right click your project, then Android Tools -> Rename Application Name:
Or, if you want to do it manually, go to your manifest file, change the package name, and make a Project Clean.
Solution 2
Check the AndroidManifest.xml
, there's a package
attribute on the <manifest>
top-level element. That is where R.java
is generated and you should be careful renaming it.
Solution 3
For those who attempt to manually change it, the statements that the R.java file is linked is correct. If you simply change it in the manifest, you will get a long sequence of "R cannot be resolved" errors throughout your java files that reference resources. To correct that you'll need to add an import for the R class in each of those files.
So if you had your package originally as: "com.mycomp.myapp.android" and changed it to "com.mynewcomp.myapp.android" you would need to go into each java class file and add:
import com.mynewcomp.myapp.android.R;
If you run the originally suggested rename command on the project this is done for you automatically.
Solution 4
I know it's an old question, but I needed it now and maybe someone else needs it too. I'm using Android Studio 2.1.1
To make it work I had to change:
- package - on AndroidManifest.xml
- applicationId - on build.gradle of the app folder
This way there was no need to import R on every java class.
It is important to remember that this is not an usual change and should not be done every time.
The link applicationId vs. package name explains the difference between them and why they should not be changed.
Solution 5
It gets named to the root package of your app. If you change your app's root package to something else, R.java will exist in that package now.
Related videos on Youtube
Bex
Updated on August 12, 2020Comments
-
Bex over 3 years
I am using eclipse and I created a test android project and the package in the "gen" folder that contains
R.java
is currently calledcom.something.test
(I thought I was just testing but build my whole app on it!)This is referenced when loading the app and the phone sometimes displays it so I need to rename it. I tried this by clicking refactor but it regenerated it again with the old name!
Can I rename it?
-
bigstones about 13 yearsI'm not 100% sure but I think you have to change the application's package name in the manifest (then rebuild).
-
-
rogermushroom about 12 yearsThis is incorrect, it's set by android:package which is different to root package
-
Dane411 over 9 yearsI followed these steps but then I got a problem because it didnt fix the package in the manifest (just in case someone else has the same problem)