0

I have a package that I want to rename in Android Studio. Here is what it looks like right now:

enter image description here

I simply want to change the package name to something shorter like com.tabs for example, but I don't seem to be able to do so. I tried to right click on it and click "Refractor" and "rename" to "com.tabs" but that doesn't seem to be able to work. I also tried to rename the package in AndroidManifest.xml by specifying package="com.tabs" but that doesn't seem to change anything either. Is there any way I can simply remove those extraneous packages (com.tabs.tabs.tabs specifically) and keep com.tabs at the end? I also tried to right click the packages but I am worried if I delete the packages, it will also delete the subdirectories. Any help would be appreciated. Thanks!

user1871869
  • 3,317
  • 13
  • 56
  • 106
  • 1
    Refactoring is the correct approach. Otherwise, you can go into the project folder with a file explorer and move those files up – OneCricketeer Jul 27 '16 at 02:38
  • 1
    Refer http://stackoverflow.com/questions/16804093/android-studio-rename-package – VVB Jul 27 '16 at 02:40
  • please refer http://stackoverflow.com/questions/16804093/android-studio-rename-package?answertab=votes#tab-top – Shubham Jain Jul 27 '16 at 02:52
  • [How to change package name](https://androidride.com/how-to-change-rename-android-app-package-name-android-studio/) – Athira Reddy Jul 18 '19 at 01:19

2 Answers2

0

Firstly, change your application id in build.gradle

android {

    defaultConfig {
        // ...
        applicationId "com.tabs"
        // ...
    }
}

Then use the IDE tools to refactor your package name.

Also, make sure the Activity/Service/ContentProvider/BroadcastReceiver names matched your new class name after do refactor.

alijandro
  • 11,627
  • 2
  • 58
  • 74
0

Refactoring (shift + F6) is sometimes a pain with long package names, so you can also just create a new package name com.tab under the java folder and drag your files/folder in there. It's still refactoring, but it's a lot easier.

And as others have said, change your applicationId (not necessary but it'll keep it consistent), as well as in your AndroidManifest and in any other xml in which the package name was used.

Allan W
  • 2,791
  • 4
  • 23
  • 41