I have changed the package name of my project, I know that this is essential when uploading the application to the play store, since after an app is published in the play store I will not be able to change this package name.
The doubt I have is that although I have already changed the name of the package, the old name still appears in the java files, but in the app level build.gradle the applicationId is shown with the new name.
What should I do to change the old name in all the files? Next, I show a fraction of build.gradle and also the main activity, since the old name still appears there. Is it necessary to change the name manually in all the files?
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId 'com.uniagustiniana.tecnologias.uniagustapp'
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName '1'
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
As it continues to appear in the other files:
package com.tecnologias.uniagustapp;
The procedure to rename your application package or refactor a package is:
a) in your project select the "gear" and unselect the option
"Compact Empty Middle Packages"
, this is important so you can select a directory which you want to refactor.Later we select the folder to refactor, with the right button we access the context menu, select the option
Refactor
andRename
.It will ask you if you want to refactor the Package, which we want:
A window will be displayed where the matches are found, you simply have to click on the button
"Do Refactor"
:There is no need to make any changes to the AndroidManifest.xml or the build.gradle as the refactoring is done on the entire project.
Luckily, with Android Studio you won't have to manually change your project's package name in every file.
1.- To do this, the first thing you will have to do is select the package of the project you are in and uncheck the option
Compact Empty Middle Packages
that you will find in the configuration wheel that is just above the project structure.2.- Once this is done, you will see that the name of your package has been divided into smaller packages. You will have to select the package you want to rename, right-click it and, on the context menu, click
Refactor > Rename...
3.- Next, a Warning will appear indicating all the files that are going to be affected and if you want to rename the package or the directory. Select
Rename Package
.4.- It will let you indicate the new name you want for your package.
5.- A screen will appear at the bottom of Android Studio indicating all the files in which the package name is going to be modified. This allows you to check if there were any places where you would not want to change it. However, since it is the name of the package, I think you might want to rename it in all occurrences of the project.
When you are convinced that you have everything checked and that you want to make the modification, you can proceed to click on the button
Do refactor
.6.- Finally, a message will appear indicating that the gradle has been modified since the last synchronization of the project. We will have to give
Sync Now
so that the project is synchronized and it does not give us problems later.In the image below you can see that the package name has already been changed.
And you would already have your package name changed throughout the Android Studio project. Simply select the option again
Compact Empty Middle Packages
to leave the compact package (as it is by default) and... voila!I have tried both ways of doing it and in my case it changed the name of the package, however when uploading the .abb file in the play store it kept showing me a warning that I had to change the name of the package. I have solved it by right clicking on the app module with the view in "Android" mode, clicking on "open module settings", section "modules", tab "default config" and changing there the value of "aplicationid" to the new name of package. I hope someone finds it helpful.