简体   繁体   English

在 Android Studio 中重命名 package 和重命名目录有什么不同?

[英]What are different between Rename package and Rename directory in Android Studio?

I add a new module for a project in Android Studio.我在 Android Studio 中为项目添加了一个新模块。 I hope to rename package, so I select Refactor -> Rename item , you can see Image 1.我希望重命名 package,所以我 select Refactor -> Rename item ,你可以看到图 1。

I find that the Image 2 is displayed to let me select between Rename package and Rename directory , I'm confused.我发现显示图像 2 让我 select 在Rename packageRename directory之间,我很困惑。

I think that the name of package and the name of directory are matched, I think that the name of directory will be changed when I change the name of package, and the name of package must be changed when I change the name of directory.我认为package的名称和目录的名称是匹配的,我认为当我更改package的名称时目录名称将被更改,并且ZEFE90A8E604A7C640E88D03A6的名称必须更改时ZEFE90A8E604A7C640E88D03A6的名称B

And more, the Image 3 is displayed when I add a new module for the project, I don't know what Application/Library name mean, I can't find the string My Library in whole project.而且,当我为项目添加新模块时,会显示图像 3,我不知道应用程序/库名称是什么意思,我在整个项目中找不到字符串My Library

Image 1图 1 在此处输入图像描述

Image 2图 2 在此处输入图像描述

Image3图3

在此处输入图像描述

Added Content添加内容

To oiyio: Thanks!致 oiyio:谢谢!

But the file string.xml file isn't be created automatically when I create a new module for the project, so I can't find the string My Library in string.xml .但是当我为项目创建新模块时,不会自动创建文件string.xml文件,所以我在string.xml中找不到字符串My Library

You can see the tree structure with Image 4, and you download the code at https://www.dropbox.com/s/jwhjb7vq4hfxfi8/MyTest.zip?dl=0 for test.您可以看到图 4 的树形结构,并在https://www.dropbox.com/s/jwhjb7vq4hfxfi8/MyTest.zip?dl=0下载代码进行测试。

Image 4图 4 在此处输入图像描述

Rename package will rename all the files which have package name imported with the new package name and rename directory will rename the directory folder and will not change the package name which is imported in each file. Rename package will rename all the files which have package name imported with the new package name and rename directory will rename the directory folder and will not change the package name which is imported in each file.

You can use the following way to rename full package name您可以使用以下方式重命名完整的 package 名称在此处输入图像描述 Alternatively, you can use the following trick to rename a package:或者,您可以使用以下技巧重命名 package:

  1. Create a new package by right clicking on the Java folder → New → Package and give it a name what you want.通过右键单击 Java 文件夹 → 新建 → Package 创建一个新的 package 并为其命名。
  2. Then, select and drag all your classes to the new package.然后,select 并将所有类拖到新的 package 中。 Android Studio will refactor the package name everywhere. Android Studio 将在各处重构 package 名称。
  3. Delete the old package.删除旧的 package。
  4. Edit the package name in AndroidManifest.xml and build.gradle file to the new package.将 AndroidManifest.xml 和 build.gradle 文件中的 package 名称编辑到新的 ZEFE90A8E604A7C8B7ED8E604A7C840.

Let me answer your last question, When I tested by creating a new module -> Android Library, as shown in your picture 3, My Library is added to strings.xml.让我回答你的最后一个问题,当我通过创建一个新模块进行测试时 -> Android 库,如图 3 所示,我的库被添加到 strings.xml 中。 If there are 2 app_name string available as shown below, the one in the app module overrides the one in the library module如果有 2 个 app_name 字符串可用,如下所示,应用程序模块中的一个会覆盖库模块中的一个在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM