full - how to change project name in android studio




Android Studio Rename Package (20)

In Android Studio, you can do this:

For example, if you want to change com.example.app to my.awesome.game, then:

  1. In your Project pane, click on the little gear icon ( )

  2. Uncheck / De-select the Compact Empty Middle Packages option

  1. Your package directory will now be broken up in individual directories

  2. Individually select each directory you want to rename, and:

    • Right-click it
    • Select Refactor
    • Click on Rename
    • 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
    • Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All

  1. Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId in the defaultConfig to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:

  1. You may need to change the package= attribute in your manifest.

  2. Clean and Rebuild.

  3. Done! Anyways, Android Studio needs to make this process a little simpler.

How do you rename packages in new IDE Android Studio, based on intelijj ?

Is there any automatic refactoring included?

I want to make bulk refactoring but I don't know how. I worked 2 years with eclipse and in eclipse it's one click operation.


  1. Goto your AndroidManifest.xml.
  2. place your cursor in the package name like shown below don't select it just place it.

  1. Then press shift+F6 you will get a popup window as shown below select Rename package.

  1. Enter your new name and select Refactor. (Note since my cursor is on "something" only something is renamed.)

That's it done.


(1)

Open the file:

app >> manifests >> AndroidManifest.xml

Highlight each part in the package name that you want to modify (don't highlight entire package name) then:

  • Mouse right click >> Refactor >> Rename >> Rename package
  • type the new name and press (Refactor)

Do these steps in each part of the package name

(2)

Open (Gradle Script) >> (build.gradle(Modul:app))

and update the applicationId to your package name

(3)

open the menu (build) and choose (Rebuild Project)


Updated answer: May 2015

OK I have been struggling with cloning & renaming projects in Android Studio, but finally I achieved it. Here are the steps to follow:

  1. Copy the project folder, rename it & open it with Android Studio
  2. Rename module directory from explorer
  3. Rename projectName.iml and content
  4. Rename idea/.name content
  5. In your Project pane, click on the little gear icon -> uncheck "Compact Empty Middle Package"
  6. Refactor src directories for new package name (rename package, "not rename directory")
  7. In build.gradle rename application id
  8. settings.gradle rename module

That's it...


After you follow one of these techniques to get your package renamed, you might start seeing errors.

If / when your R.java is not getting generated properly, you'll get a lot of errors in your project saying error: cannot find symbol class R and also error: package R does not exist.

Remember to check your Application manifest xml. The manifest package name must match the actual package name. It seems the R.java is generated from the Application Manifest and can cause these errors if there's a mismatch.

Remember to check the package attribute matches in your <manifest package="com.yourcompany.coolapp">


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. AndroidStudio will refactor the package name everywhere.

Finally, delete the old package.

Done.

One more thing very important

You have to Change manually AndroidManifest.xml and build.gradle file to the new package if you use this method.


Best way to write the new package name and drag from older package name. Second way if you click Refactor then move option then rename the package name , It will rename the package name then rebuild.

In Build.gradle You have to do manually , If u Refactor then it will not rename in Build.gradle.


Changing the application ID (which is now independent of the package name) 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.

Note this will not change the package name. The decoupling of Package Name and Application ID is explained here: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename


I have seen the top voted answers but i found is a little bit different to do this, i try to do the most complete tutorial.

From the Android Studio click over the gear icon ( ) and then select the option: "Compact Empty Middle Packages", to see the folders separated in a tree view.

Now select the folder, click right button to open the contextual menu, select Refactor and then Rename

You will be advised to refactor the package:

Then a window will show the coincidences inside the proyect, select "Do Refactor":

We don´t have to change manually the AndroidManifest.xml or build.gradle files, Refactoring the package will do the job!.


I recommend to use the Sublime Text(or Notepad++). Replace com.one.lastname -> com.two.newname and com/one/lastname -> com/two/newname in ...\Projects[MyProject]. and don't forget to rename ...\Projects\MyProject\app\src\main\java\com\one\lastname, ...\Projects\MyProject\app\src\test\java\com\one\lastname and ...\Projects\MyProject\app\src\androidTest\java\com\one\lastname! That's all:)


I've found a way easier solution to this problem which also changed the generated imports like com.test.testpackagechange.R and only takes about a minute.

Your first step is to open Android Studio and open the replace all window (Mac: cmd + shift + R, Windows I assume: ctrl + shift + R). Type in your old package name and in the one below your new package name. Click Find. This may take a while because it is also looking through the generated items. If it has over 1000 hits, just click continue.

After you've done that push Replace All to replace your old package name with your new one.

Now close Android Studio and go to Finder on Mac or Windows Explorer on Windows. Change the name of the folders to your new package name, like this:

Now open Android Studio again. Gradle will sync and your package name should be changed to the new one.

I've found this to be the easiest one and the one that covers all areas like generated files.


If your package name is more than two dot separated, say com.hello.world and moreover, you did not put anything in com/ and com/hello/. All of your classes are putting into com/hello/world/, you might DO the following steps to refactoring your package name(s) in Android Studio or IntelliJ:

  • [FIRST] Add something under your directories(com/, com/hello/). You can achieve this by first add two files to package com.hello.world, say
   com.hello.world.PackageInfo1.java
   com.hello.world.PackageInfo2.java

then refactor them by moving them to com and com.hello respectively. You will see com and com.hello sitting there at the Project(Alt+1 or Command+1 for shortcut) and rename directories refactoring is waiting there as you expected.

  • Refactor to rename one or more of these directories to reach your aim. The only thing you should notice here is you must choose the directories rather than Packages when a dialog ask you.

  • If you've got lots of classes in your project, it will take you a while to wait for its auto-scan-and-rename.

  • Besides, you need to rename the package name inside the AndroidManifest.xml manually, I guess, such that other names in this file can benefit the prefix.

  • [ALSO], it might need you to replace all com.hello.world.R to the new XXX.XXX.XXX.R(Command+Shift+R for short)

  • Rebuild and run your project to see whether it work. And use "Find in Path" to find other non-touch names you'd like to rename.

  • Enjoy it.

Packages serve two purposes. One is to uniquely identify your app in the Google Play Store. The other is to name the package for the R.java class which is generated when you build your project. You can think of the first purpose as the external package and the second as the internal package. Assuming you want to change the external package so you can identify in the Play store, there's a convenient way to do this.

In Android Studio, choose File > Project Structure > Choose your app's module > Click on the Flavors tab > change the Application id. Now, when you build your project, your APK and manifest will use this new package name.


Please try the following steps:

  1. Click on setting gear icon and deselect Compact Empty Middle Package
  2. Now we can see each package folder is broken into parts
  3. Now right click on the first package folder >>> refactor >>> rename
  4. Now a warning will be displayed but you go ahead and click Rename Package
  5. After that enter your domain name for the package name
  6. Click on ‘Do Refactor’
  7. Now it has change the package domain name of the App. Now Change the domain extension and App folder name according to your requirement
  8. Now open build.gradle (Module: app) in Gradle Scripts. Here change the application id and click Sync Now.

*******Finally it’s done ******


Right click on package -> refactor and change the name. You can also change it in manifest. Sometimes if u change package name but after creating apk it shows different package name at that time check "applicationId" in build.gradle file.


Right-click on the package at the Project Panel.

Choose Refactor -> Rename from the context menu.


The approach used by me for renaming the package name is simple as follows:-

Step 1 : Select the Project option from left menu of Android Studio

Step 2 : Right click on java and add a new package and set the desired package name

Step 3 : Enter you new packagename

Step 4 :Copy all the files from your old package and paste in the new package

Step 5 :Rename the package name in manifest file

Step 6 :Rename the package name in build.gradle file

Step 7 :Then right click the old package and delete it with all its data, and delete that directory as well

Step 8 :Then Rebuild your project

Step 9 :Then you will find some errors of old import packagename in your project Select the old package name in any file and press CTRL + Shift + R , and enter you new package name in replace box, then press find

Step 10 :Then a popup appears like below and select All files option from it

Step 11 :Rebuild your project again, bingo your project packagename has been changed :)


The common mistake that one can make is one cannot rename the package structure i.e it is not possible to change com.name.android to com.Renamed.android when one tries to modify at com.name.android level.

In order to have the same desired change go one level up i.e com.name and here when you refactor change it to Renamed. This will work always


This I believe what you are looking for is Refactor > Move. You can also press F6.

You will get two popups. Make sure you select rename package on both. After that you will get a pop up to place the new package name.

Please note that if your package name is, for example, com.example.android.projectname then this will let you change com.example.android to something else.

One more thing, this will update the applicationId in your build.gradle as well. Just make sure that the checkboxes for "search in comments and strings" and "search for text occurrences" are both checked for it to work.


ctrl+shift+R has always worked for me. Simply replace all and choose All Files.







android-studio