Android Studio Rename Package

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.


In Android Studio, you can do this:

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

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

  • Uncheck / De-select the Compact Empty Middle Packages option

  • 紧凑的空中间包

  • Your package directory will now be broken up in individual directories

  • 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
  • 在这里输入图像描述

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

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

  • Clean and Rebuild.

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


  • 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 Android Manifest and gradle file to the new package if you use this method.


    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:

  • right click on the root folder of your project.
  • Click "Open Module Setting".
  • Go to the Flavours tab.
  • 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

    链接地址: http://www.djcxy.com/p/25490.html

    上一篇: Android BackupAgent从未调用过

    下一篇: Android Studio重命名包