重命名Android Studio中的程序包 [英] Rename package in Android Studio

查看:67
本文介绍了重命名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选项

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

      1. 现在打开您的 Gradle Build File (build.gradle-通常为appmobile).如果尚未自动更新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.

      清理并重建.

      1. 完成! 无论如何,Android Studio需要使此过程更加简单.

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

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