Renaming a package created by R.java to

I use eclipse, and I created a test project for Android, and the package in the "gen" folder containing R.java is currently called com.something.test (I thought I was just testing, but com.something.test my entire application on it! )

This is indicated when downloading the application, and the phone sometimes displays it, so I need to rename it. I tried this by clicking refactoring, but he restored it again with the old name!

Can I rename it?

+42
java android eclipse r.java-file
Mar 30 2018-11-11T00:
source share
7 answers

Right-click your project, then Android Tools -> Rename Application Name:

enter image description here

Or, if you want to do this manually, go to the manifest file, change the package name and do Project Clean.

+85
Mar 30 2018-11-11T00:
source share

Check out AndroidManifest.xml , there is a package attribute of the top-level <manifest> element. This is where R.java is generated, and you should be careful to rename it.

+19
Mar 30 '11 at 14:36
source share

For those trying to manually modify it, the assertions associated with the R.java file are true. If you just change it in the manifest, you will get a long sequence of "R cannot be resolved" errors in your java files that reference resources. To fix this, you need to add import for class R to each of these files.

So, if you had the package initially: "com.mycomp.myapp.android" and changed it to "com.mynewcomp.myapp.android", you will need to go into each java class file and add:

import com.mynewcomp.myapp.android.R;

If you run the originally proposed rename command in a project, this will be done for you automatically.

+3
Jun 24 '11 at 17:36
source share

It gets the name in the root package of your application. If you change your root application package to something else, R.java will exist in this package.

+2
Mar 30 2018-11-11T00:
source share

Another thing to check is to have custom views with xml namespaces. It took me a minute to figure out that I needed to change the xmlns attribute.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myxmlnamespace="http://schemas.android.com/apk/res/com.mynew.packagename" ... 
+1
Apr 29 '14 at 18:10
source share

I know this is an old question, but I need it now, and maybe someone needs it too. I am using Android Studio 2.1.1

To make it work, I had to change:

  • package - on AndroidManifest.xml
  • applicationId - on build.gradle application folders

Thus, it was not necessary to import R into each java class.

It is important to remember that this is not an ordinary change and should not be done every time.

The applicationId link against the package name explains the difference between them and why they should not change.

+1
Aug 11 '16 at 19:41
source share

I reorganized my package one by one using Right Click-> Refactor and Android Manifest.XML. My R file was still built on the old package name.

Closing and opening the project fixed this problem, but I needed to make a manual change in all my java files.

0
Sep 24 '12 at 6:19 06:19
source share



All Articles