Rename package in Android Studio

2018-12-31 01:09发布

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 refactoring, but I don't know how. I worked two years with Eclipse and in Eclipse it's a one-click operation.

30条回答
步步皆殇っ
2楼-- · 2018-12-31 01:37

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?

查看更多
爱死公子算了
3楼-- · 2018-12-31 01:37

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

查看更多
只靠听说
4楼-- · 2018-12-31 01:39
  1. Select option enter image description here

  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 enter image description here

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

  8. After Changes done enter image description here

查看更多
梦寄多情
5楼-- · 2018-12-31 01:40

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

查看更多
美炸的是我
6楼-- · 2018-12-31 01:40

Right-click on the package at the Project Panel.

Choose Refactor -> Rename from the context menu.

查看更多
低头抚发
7楼-- · 2018-12-31 01:41

(1)

Open the file:

app >> manifests >> AndroidManifest.xml

enter image description here

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

enter image description here

(2)

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

and update the applicationId to your package name

enter image description here

(3)

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

查看更多
登录 后发表回答