Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change package name in android studio? [duplicate]

I have made an app and it is my very first app so when I started coding, I left the package name as com.example.stuff and now when I try to upload to the play store it wont let me due to the package name. I have tried refactor-> rename the package name and changed it in the AndroidManifst.xml then I tried to upload again. I am once again left with the same message time after time.

I appreciate any help and thanks in advance. :)

like image 743
Thaej Sooriya Avatar asked Sep 15 '14 12:09

Thaej Sooriya


People also ask

Can I rename package in Android Studio?

Step by Step Implementation Step 2: Now click on the setting gear icon and deselect Compact Middle Packages. Step 3: Now the packages folder is broken into parts as shown in the below image. Step 4: Now right-click on the first package name (com) and Refactor > Rename.

Can we rename the package name?

In the Pop-up dialog, click on Rename Package instead of Rename Directory. Enter the new name and hit Refactor. Click Do Refactor in the bottom. Allow a minute to let Android Studio update all changes.

Can two apps have same package name?

No, every app should have a unique package name. If you install an app with a package name which is already used in another installed app, then it will replace it.


4 Answers

First click once on your package and then click setting icon on Android Studio.

Close/Unselect Compact Empty Middle Packages

Then, right click your package and rename it.

Thats all.

enter image description here

like image 68
Mehmet Avatar answered Oct 05 '22 19:10

Mehmet


In projects that use the Gradle build system, what you want to change is the applicationId in the build.gradle file. The build system uses this value to override anything specified by hand in the manifest file when it does the manifest merge and build.

For example, your module's build.gradle file looks something like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        // CHANGE THE APPLICATION ID BELOW
        applicationId "com.example.fred.myapplication"
        minSdkVersion 10
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
}

applicationId is the name the build system uses for the property that eventually gets written to the package attribute of the manifest tag in the manifest file. It was renamed to prevent confusion with the Java package name (which you have also tried to modify), which has nothing to do with it.

like image 38
Scott Barta Avatar answered Oct 05 '22 19:10

Scott Barta


It can be done very easily in one step. You don't have to touch AndroidManifest. Instead do the following:

  1. right click on the root folder of your project.
  2. Click "Open Module Setting".
  3. Go to the Flavours tab.
  4. Change the applicationID to whatever package name you want. Press OK.
like image 22
Moj Avatar answered Oct 05 '22 19:10

Moj


Another good method is: First create a new package with the desired name by right clicking on the java folder -> new -> package.

Then, select and drag all your classes to the new package. Android Studio will refactor the package name everywhere.

Finally, delete the old package.

or Look into this post

like image 36
Sagar Pilkhwal Avatar answered Oct 05 '22 19:10

Sagar Pilkhwal