How to rename a package in Android Studio

- Andrés Cruz

En español
How to rename a package in Android Studio

Wanting to rename the package name of a project in Android can be due to many factors, among the main ones would be that it has been decided to give the application another name and very possibly the name of the application is part of the package name.

However, this can cause problems if we do not do it properly and we can render the project useless in the process; however, performing the renaming in the correct way is very easy and consists of very few steps as we will see below.

Renaming the package name in Android Studio

To rename the package we go to our panel in our project on the name of the package, right click on the gear icon and deselect the Compact Empty Middle Packages option:

Opción Compact Empty Middle Packages

Now we can change the names of the packages independently without any problem; see this comparison of how the section that identifies the package name looks in our project tree:

Opción Compact Empty Middle Packages desabilitada

We are simply changing one by one the folders that correspond to the name of each package; that is, if the package name is divided into several parts (as is the usual example: com.example.app -it is made up of three parts-) we must rename each of these parts independently; Right click on the package part and on the Rename package button:

Opción renombrar

And then we put the name and on Refactor:

Opción refactor

We must do this for each part of the package name that we want to change; Once this is done, we go to the build.gradle in our applicationId and change the previous name to the new name produced by the previous steps.

applicationId "net.desarrollolibre.notification.notificacion"
By:

applicationId "net.desarrollolibre2.notification2.notificacion"
Generally the name of the package has the same name as the names of the folders or directories that make up our project, for this instead of clicking on "Rename package" we click on "Rename directory", we put the name and then click on "refactor".

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.