Rename package in Android Studio

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

    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 :)

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

    How to rename com.example.app to com.android.app:

    1. in package com.example.app select example

    2. Shift + F6

    3. choose rename package

    4. rename example to android

    5. confirm do refactor

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

    The best way is to write the new package name and drag from the older package name.

    The second way, if you click Refactor then move option then rename the package name, it will rename the package name and then rebuild.

    In Build.gradle you have to do manually, if you Refactor then it will not rename in Build.gradle.

    0 讨论(0)
  • 2020-11-21 05:56
    1. Select option

    2. Uncheck the Compact Empty Middle Packages option.

    3. Select which directory you want to change(I have selected 'crl' shown in step 6).
    4. Shift+F6
    5. Rename Package
    6. Renaming directory crl to crl1

    7. Finally click on Do Refactor button marked in image below enter code here

    8. After Changes done

    0 讨论(0)
  • 2020-11-21 05:59
    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).

    0 讨论(0)
  • 2020-11-21 06:00

    Another good method is: First create a new package with the desired name by right clicking on the Java folder → NewPackage.

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

    Finally, delete the old package.

    Done.

    Very important:

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

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