在 Android Studio 中重命名包 [英] Rename package in Android Studio

查看:36
本文介绍了在 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,则:

  1. 在您的项目窗格中,点击小齿轮图标 ( )

  1. In your Project pane, click on the little gear icon ( )

取消选中Compact Empty Middle Packages 选项

您的包目录现在将被分解为单独的目录

Your package directory will now be broken up into individual directories

单独选择要重命名的每个目录,然后:

Individually select each directory you want to rename, and:

  • 右键单击它

    • Right-click it

      选择重构

      点击重命名

      在弹出的对话框中,点击Rename Package 而不是 Rename Directory

      In the pop-up dialog, click on Rename Package instead of Rename Directory

      输入新名称并点击重构

      点击底部的进行重构

      请稍等片刻,让 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

      1. 现在打开您的 Gradle 构建文件(build.gradle - 通常是 app移动).将 defaultConfig 中的 applicationId 更新为您的新包名称和同步 Gradle(如果尚未自动更新):

      1. Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId in the defaultConfig 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 需要让这个过程更简单一些.

      Done! Anyway, Android Studio needs to make this process a little simpler.

      这篇关于在 Android Studio 中重命名包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆