Rename package in Android Studio

后端 未结 30 1896
深忆病人
深忆病人 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:50

    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.

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

    Right-click on the package at the Project Panel.

    Choose Refactor -> Rename from the context menu.

    0 讨论(0)
  • 2020-11-21 05:52
    1. Select the package name in the Java folder.
    2. Shift+F6
    3. Change the package name and click OK.

    Your package name will be changed from all the Java files and the manifest file. You have to manually change the package name from build.gradle.

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

    IntelliJ IDEA has an option called "Compact Empty Middle Packages". Select the option icon of the Project tab and de/activate this.

    See: How can I change top level package name in IntelliJ IDEA?

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

    Change the Package Name


    To rename your package name, all you have to do is go to your AndroidManifest.xml file, put your mouse cursor in front of the part of the package name you want to change.



    Right-Click > Refactor > Rename



    In the new window press Rename package



    Change name and press Refactor



    …and press Do Refactor at the bottom.



    Your package name usually is in format com.domain.appname, in this example we changed the appname part, but you can do the same steps for the domain too.

    Done! You changed your package name!

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

    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

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