0

I have read almost 10-12 answer on how to change package name but every answer failed to do his job. There are errors after renaming the packages like the old imports are presents.

ex: suppose the old package was com.example.x after changing I made it in.ex.x but in every class file the old imports are present, such as com.example.x.something.

How to rename packages without error?

Shantanu Patil
  • 43
  • 2
  • 11

5 Answers5

0

Have you try this (assuming you're using Android Studio) :

  • open Manifest
  • right click on the package name instead the application tag > Refactor
  • select to refactor the package name
  • set a new package name
  • validate the modifications

That is.

Bruno
  • 3,872
  • 4
  • 20
  • 37
0

In your Project pane, click on the settings icon

Select / De-select the Empty Middle Packages option

Your package directory will be individual directories

Right click -> refactor -> rename -> Rename the package.

Mani Vasagam
  • 820
  • 5
  • 10
  • did the same but it create another package with the new name specified and does not delete the old package also it does not change content (imports) in each class file – Shantanu Patil Aug 17 '18 at 10:01
  • refer this link: https://stackoverflow.com/questions/16804093/android-studio-rename-package – Mani Vasagam Aug 17 '18 at 10:04
0

First you need to edit the package name in build.gradle (app)

applicationId "com.myapplication"

Open the TODO tab in the toolbar under the IDE (Android Sdtudo) it includes Android Profiler, Logcat, v.v... Then you can right click on the name of the package you want to change, select Refactor-> Rename, after entering the new name you can click on Refactor button and see below tab TODO 2 button Refactor and Cancel. Click Do Refactor you will see it change successfully.

Chanh
  • 433
  • 3
  • 12
0

For example, if you want to change com.example.x to in.ex.x --->

  • In your Project pane, click on the little Gears icon
  • Uncheck / De-select the Compact Empty Middle Packages option
  • Your package directory will now be broken up in individual directories
  • Individually select each directory you want to rename, and:

     1) Right-click it
     2) Select **Refactor**
     3) Click on **Rename**
     4) In the Pop-up dialog, click on **Rename Package** instead of Rename Directory
     5) Enter the new name and hit **Refactor**
     6) Click **Do Refactor** in the bottom
     7) Allow a minute to let Android Studio update all changes
    

Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All

  • Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:
  • You may need to change the package= attribute in your manifest.
  • Clean and Rebuild.
SolveProblem
  • 83
  • 1
  • 9
0

you can change package name from left side ProjectView

-> select your package name by clicking
-> press shift+F6 and select Rename Package Check this image it might help you