Change Package Name in Android (Motodev / Eclipse)

Changing your project package in Motodev Studio or Eclipse is always tricky and takes time to master. We’ll continue with our previous example of Re-ordering a list and modify its package name. The package name we used in this project was “com.movivation.reorderingdemo”. Let’s start Motodev Studio for Android 3.1 and begin this journey.

Now, we’ll be changing it to look like “com.movivationlabs.reorderingdemo”. 

 To change the name of your package, right click on package name, then select “Refactor” -> “Rename” as shown in the above image. After clicking “Rename”, you’ll see a window that resembles like this : 

After changing the package, this window will look like :

On clicking the “OK” button on this dialog, Motodev Studio for Android processes your requirement to change the package name. The process takes a minute second to complete and you can see the changes here :

 The first step of changing the package name is now completed. The next step is to change the package name using Android Tools found in the IDE. Right-click the “Project Name” in Project Explorer window, then click on “Android Tools” and at last click on “Rename Application Package”.

On clicking that menu item, opens another dialog asking for new package name:

The same dialog after changing the package name, the dialog looks like:

On affirming the changes, the IDE shows a very informative, line-by-line view of all the files that will be changed, and asks for final confirmation:

Clicking the “Finish” button starts the making the changes in all the mentioned files and finally the IDE asks for us to update the launch configuration:

 This concludes the second step in changing the package. Now, all the files such as java source codes and Android manifest will be containing the newly proposed package. Look at the manifest file:

 Our Re-ordering demo project was very small project with only one activity and a layout and that layout too, didn’t have any custom controls or UI controls that we extend in our project. The problem with Motodev and, in turn, Eclipse is that if we were to extend a UI control object, then the respective IDE won’t be able to modify the package name in the extended UI control object.

Below is the extended ImageView control named “TouchImageView”:

This control is not used in our project, I’ve shown this control only to make you understand that we need to modify package names for any custom control we use. This is the final step in changing the package name of an Android project.

In summary,

  • Refactor-rename the android package name.
  • Rename the package name using Android Tools.
  • Manually change the package in Android manifest or any other custom controls, styles, themes you’ve used in your project, if not changed otherwise.

That concludes the tutorial for today. Hope it is useful to all the Android-ers!

Advertisements
By Movivation Labs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s