Rename package in Android Studio

后端 未结 30 1969
深忆病人
深忆病人 2020-11-21 05:21

How do you rename packages in the new IDE Android Studio, based on IntelliJ IDEA?

Is there an automatic refactoring included?

I want to make bulk refactorin

相关标签:
30条回答
  • 2020-11-21 05:45
    1. Goto your AndroidManifest.xml file.
    2. Place your cursor in the package name like shown below. Don't select it, just place it.

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

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

    That's it done.

    0 讨论(0)
  • 2020-11-21 05:45

    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.

    0 讨论(0)
  • 2020-11-21 05:47

    Select the package that will be refactored. RefactorMove"Move xxx to new package".

    0 讨论(0)
  • 2020-11-21 05:48

    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.

    0 讨论(0)
  • 2020-11-21 05:48
    1. Press Ctrl + Shift + R

    2. Replace the old package with the new one.

    3. Right click on the package name.

    4. Refactor > Rename and rename to the new one

    0 讨论(0)
  • 2020-11-21 05:50

    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...

    0 讨论(0)
提交回复
热议问题