9

I Was Created an android application with package name of com.example.******.sample . I need to refactor the package name into org.newOrg.*******.sample . I was already tried refactor method. But its parent "com" was not changed into "org" . Tell me any solution to refactor the entire package name.

Thanks in advance

7
  • 1
    press Shif+f6 then do rest of things. Commented Oct 12, 2015 at 12:38
  • refer this link stackoverflow.com/questions/16804093/… Commented Oct 12, 2015 at 12:40
  • Please see this link.it's helpful for you:- stackoverflow.com/questions/25848046/… Commented Oct 12, 2015 at 12:44
  • Perfect and Clear demo @Naveen . Thanks Commented Oct 13, 2015 at 3:55
  • Thanks Rustam and Pranav Commented Oct 13, 2015 at 4:02

5 Answers 5

18

This modification needs three steps :

  1. Change the package name in the manifest
  2. Refactor the name of your package with right click -> refactor -> rename in the tree view, then Android studio will display a window, select "rename package"
  3. Change manually the application Id in the build.gradle file : android / defaultconfig / application ID Then clean / rebuild the project
Sign up to request clarification or add additional context in comments.

3 Comments

Good Solution @ Gaurav Polekar
The above all solutions little bit same and works much better than other collapsing solutions. From the above all solutions, Naveen's explanation is pretty clear to see. Thanks to all who share different ways to renaming the package name.
5

In Android Studio, you can do this by following these 4 steps:

1) Click on the little gear icon on Project Pane

2) Uncheck the Compact Empty Middle Packages option

3) Now you can rename each package by right-click & then refactor it, remember to select Rename Package on popup rather Rename Directory

4) Update the package in build.gradle

5) And update google-services.json is you are using it (i.e. FireBase).

1 Comment

Point no 2) save my life (:
1

click on Settings in the project window uncheck the Compact Empty Middle Packages

It will separate the app package and you can rename it one after another.Also change the App Id inside build.gradle under defaultConfig section

defaultConfig { applicationId "com.foocomp.android" } 

enter image description here

Comments

0

You can use replace function like click right on project main folder and click replace with choose. Then you can replace package name. I used it more times and it works.

Comments

0

You can use the plugin "Android Package Renamer", it is available on Android Studio Marketplace and Intellij IDEA. It can complete several cases, and one of them contains your case.

This plugin can rename packages in android project, here are a few specific cases (it can do more)::

  • com.android.example -> org.nickseven.product
  • com.android.example -> org.nickseven
  • com.android.example -> org.nickseven.product.native
  • com.android.etc.nick.d -> org.android.otd.nick.d
  • ....etc

What you need to do is download it and use the following:

  • Open Your Project.
  • Click -> File -> Rename Package
  • Input the Package you want to change.
  • Click OK.
  • Sync Project with Gradle Files or Invalidate Caches

You can see the detailed answer here and the official github repo here for more detailed instructions.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.