How to change the name in the android application package?

4

The current name of my package is com.newapp.nomedopacote . Well, in case I want to change it to com.newapp.novopacote , without any damage to the application. I tried to simply do a refactor and it lost the R file.

How can I do this?

    
asked by anonymous 21.02.2015 / 03:41

1 answer

3

Well, beforehand, I just wanted to tell you that the R class is always created after Build. So if you changed the package for your project, remember to give clean project and then build project . Okay, now let's change the package for your project.

  

Change package in app / build.gradle

defaultConfig {
        applicationId "co.mypack.myoldpack"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "R15.0c"
}
  

Change line applicationId to your new package

defaultConfig {
        applicationId "co.mypack.mynewpack"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "R15.0c"
}
  

Change package in AndroidManifest.xml

package="co.mypack.myoldpack"

After changing the above line to package="co.mypack.mynewpack" , you will have to create a new package in main/java/. and then pass all your classes (copy and paste) to the new package and, finally, delete your package ancient.

    
21.02.2015 / 04:26