开发者

How to change package name of Android Project in Eclipse?

I have an Android project created in Eclipse. I want to modify the package name and application of the project. How do I do that in Eclip开发者_C百科se?


This is a bug in the Eclipse Android tools.

To fix: Right click on the project, go to Android tools -> Rename application package.

And also check AndroidManifest.xml if it updated correctly. In my case it didn't, and that should solve this problem.


As usual, by pressing F2 on the package name, you can rename or change the package name, and also by right-clicking and then select Rename option, you can change or rename the package name.

When you press F2, it will show you the dialog box as:

How to change package name of Android Project in Eclipse?

In this dialog, don't forget to check the "Update references" checkbox because by making "check" to this check-box, it will make changes to all the references of the package which are referred by other components of project.


None of these worked for me, they all introduced errors.

The following worked for me:

  • Right click the project and select Android Tools >> Rename Application Package.
  • Enter the new Package name
  • Accept all the automatic changes it wants to make
  • Say yes to update the launch configuration


One extremely important notice:

NEVER use a direct package names as in something similar to passing a string value containing the package name. Use the method getPackageName(). This will make the renaming dynamic. Do whatever to reach the method getPackageName().

In Eclipse Juno, the correct way of renaming is:

  1. Go and edit the manifest.
  2. Remove every old package name in the manifest.
  3. Put instead of the old package name, the new package name in every location inside the manifest. You might have classes (Activities that is) that need direct package name references.
  4. Save the manifest.
  5. Then right click the package name inside the project.
  6. Select "Refactor".
  7. Select "Rename".
  8. Type the new package name.
  9. Select "update references".
  10. Press OK and you're done and watch out also what should be done to replace the new name.
  11. Don't forget to also update the layout XML files with the new package name. You might have a custom View. Look for them.


 Right click on your project name and select Android Tools , then click 
 Rename Application Package, then change your project name click OK and 
 click Finish.

How to change package name of Android Project in Eclipse?

How to change package name of Android Project in Eclipse?

How to change package name of Android Project in Eclipse?


To change the app name when in Android, go to res/values/strings.xml and change app_name to what you want.


Just right click on the project name and select Android tools and click Rename Application Package name and rename it. It's only for Android projects.


Press F2 and then rename it (or right click on the project and select Rename). It changes wherever that package is declared in your project. It's automatically renamed all over.


Goto the Src folder of your Android project, and open the Java file.

Change the package OldName.android.widget to newName.android.widget.

It gives you an error like this

The declared package "newName.android.widget" does not match the expected package "OLDName.android.widget.

To fix this problem, select Move filename.Java to Newname.android.widget and delete the old package folder.

Next step: Go to AndroidManifest.xml and change package="OldName.android.widget" to package="newName.android.widget".


This worked perfectly for me (simple text replace):

Go to search -> file

Containing text: old pakage name

File name pattern: *

Scope: workspace

Press Replace

Replace: new package name

Now your project is full of errors.

Click your package in project explorer and press F2 (rename).

Fill in the new package name and check all checkmarks.

Press Preview.

Click OK.

Wait for Eclipse to refresh. If there are still errors, clean all projects in the workspace:

Project -> Clean


None of this worked for me until I combined the two answers mentioned in this post.

Step 1: Right click on the project -> Select Android Tools -> Rename application Package. (This will change all the files in the gen folder and in AndroidManifest but will not change the package name in the src folder so I followed Step 2)

Step 2: Inside src folder Right Click your package name -> Refactor -> Rename -> Enter the new name that you entered in Step 1.

Just to make sure Check AndroidManifest if there is still the old package name and replace with the new one (in my case inside the "uses-permission" tag).

Then close the Eclipse and Reopen it. Uninstall the app from your device and install it again and everything should be working fine.

Hope this helps and saves your time.


OK here's what I had to do:

Problem: I had a base project that I wanted to use as a starting point for several other projects that would be in the same workspace as the base project. The base project was already under GiT control in my own local repo. It was time to duplicate the base project, "MyBaseApp", to become the starting point for "MyKillerApp."

Solution:

  1. I just duplicated the overall MyBaseApp directory as MyKillerApp and had the two directories side-by-side.
  2. I edited file MyKillerApp->.project and changed the name from MyBaseApp to MyKillerApp. (This was necessary for step 3 to work.)
  3. I opened Eclipse and did a File->Import of MyKillerApp (I left out some details about how to use the Import menu, but click around, you'll figure it out.)
  4. I right clicked on MyKillerApp in the package manager and chose Android Tools->Rename Application Package to MyKillerApp. I checked all the options for renaming except the last checkbox about non-java files.
  5. I highlighted src->com.myname.MyBaseApp in the package manager and did an F2 to MyKillerApp. Then I did the same to a few classes including my opening activity class thing that goes into your AndroidManifest.xml file.
  6. I had to update a few function call names but the compiler pointed them out to me handily.

Thus I had a new project derived from a base project with no nomenclature left over from the base project and it was in its own local GiT repo.


Following worked for me in eclipse:

Go to AndroidManifest, search and replace old package name with new one and update everything when saving. Go to your root project package then press F2, write new name, and check Update References and Rename subpackages check boxes. After this everything was red in project (complaining about R import for every java file) because it wasn't changing closing tag of my custom view-s in layout xmls. After I changed these manually, everything was back to normal. That is it.


Renaming an Application- The Complete Guide

**A) for changing Just the application name
   (App name which is displayed below icon)
    in the Manifest.xml file, in <application tag, 
    android:label="YourAppName"
    then do the same in All the <activity Tags        

  B) For changing EVERYTHING 
   (folder names, Package names, Refrences,app name, etc.)
  *1) Renaming package names in gen folder and manifest.xml
      Right Click on Your project
      Android tools- Rename Application Package

  *2) Renaming package names in src folder 
      Expand src folder, Click on package (Single click) 
      Press Alt+Shift+R
      Check Update references and Rename subpackages      
   3) Renaming the app's main Folder (Optional)
      click on the application's folder (Single click)
      then Press Alt+Shift+R 

   4) Renaming application name- Refer "A)"**


Just get Far Manager and search through for the old name. Then manually (in Far Manager) replace everywhere. Sadly, this is the only method that works in 100% of the possible cases.


I had big trouble with this too.

I renamed the project and the package via refactoring, but it rendered the app useless. I renamed it back to the original and used the Android tools to rename the package and this worked, but my package folder and classes had the old name.

I then refactored the package folder. Now the app wouldn't run. My manifest was a mess. It doubled up my launcher name for example, com.ronguilmet.app/com.ronguilmet.com.class. I fixed that, and I had to manually edit all activities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜