How to change the name in the android app package?

Asked

Viewed 15,733 times

3

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

How can I do?

1 answer

3

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

Change package in app/build.Gradle

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

Change applicationId line for your new package

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

Change package on Androidmanifest.xml

package="co.mypack.myoldpack"

After changing the line above 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 old package.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.