重命名Android Studio中的程序包 [英] Rename package in Android Studio
问题描述
如何基于IntelliJ IDEA在新的IDE Android Studio中重命名程序包?
How do you rename packages in the new IDE Android Studio, based on IntelliJ IDEA?
是否包含自动重构?
我想进行批量重构,但是我不知道如何做.我在Eclipse工作了两年,在Eclipse中是一键式操作.
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.
推荐答案
在Android Studio中,您可以执行以下操作:
例如,如果要将com.example.app
更改为my.awesome.game
,则:
-
在您的 项目窗格 中,单击小齿轮图标()
In your Project pane, click on the little gear icon ( )
取消选中/取消选择Compact Empty Middle Packages
选项
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
选择
Refactor
单击
Rename
在弹出对话框中,单击
Rename Package
而不是重命名目录"In the Pop-up dialog, click on
Rename Package
instead of Rename Directory输入新名称,然后点击重构
Enter the new name and hit Refactor
点击底部的进行重构
请稍等一下,让Android Studio更新所有更改
Allow a minute to let Android Studio update all changes
注意:在Android Studio中重命名
com
时,它可能会发出警告.在这种情况下,选择 重命名所有Note: When renaming
com
in Android Studio, it might give a warning. In such case, select Rename All-
现在打开您的 Gradle Build File (
build.gradle
-通常为app
或mobile
).如果尚未自动更新defaultConfig
中的applicationId
,则将其更新为新的程序包名称和同步Gradle:
Now open your Gradle Build File (
build.gradle
- Usuallyapp
ormobile
). Update theapplicationId
in thedefaultConfig
to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:
您可能需要更改清单中的
package=
属性.You may need to change the
package=
attribute in your manifest.清理并重建.
- 完成! 无论如何,Android Studio需要使此过程更加简单.
这篇关于重命名Android Studio中的程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-