简体   繁体   English

如何安全地更改 Android Studio 中的项目名称?

[英]How to change the project name in Android Studio safely?

I want to change the project name in Android Studio.我想在 Android Studio 中更改项目名称。 I have found some answers on Stackoverflow but it didn't work for me.我在 Stackoverflow 上找到了一些答案,但对我不起作用。 Please suggest me some suitable solution.Currently I'm using Android Studio 2.3.请建议我一些合适的解决方案。目前我使用的是 Android Studio 2.3。
Thanks always :)永远感谢:)

You need to perform a few steps您需要执行几个步骤

  • First move to project view and click on the small settings icon on the top right corner of project view, make sure the compact empty middle packages option is checked首先移动到项目视图并单击项目视图右上角的小设置图标,确保选中紧凑空中间包选项
  • Right click on your java folder and choose Refactor>Rename>change to your desired package name and confirm Refactor右键单击您的 java 文件夹并选择 Refactor>Rename>change 到您想要的包名称并确认 Refactor
  • than you MUST also change the project id in your build.gradle file比您还必须更改 build.gradle 文件中的项目 ID
  • double check if your android manifest.xml refactored too(android studio should take care of it automatically but check again) this is the only method that changed the project name from the base for me.仔细检查你的 android manifest.xml 是否也重构了(android studio 应该自动处理它,但再次检查)这是我从基础更改项目名称的唯一方法。

This did the trick for me:这对我有用:

  • Close android studio关闭安卓工作室
  • Change project root directory name更改项目根目录名称
  • Open android studio打开安卓工作室
  • Open the project(not from local history but by browsing to it) Clean project打开项目(不是从本地历史记录而是通过浏览)清理项目

Check this: https://stackoverflow.com/a/28324892/4161284检查这个: https : //stackoverflow.com/a/28324892/4161284

Perform the following Steps :执行以下步骤

Step 1 - Rename:第 1 步 - 重命名:

第 1 步 - 重命名

Step 2 - Update app name in String file:第 2 步 - 更新字符串文件中的应用程序名称:

第 2 步 - 更新字符串文件中的应用程序名称

What helps for me is:对我有帮助的是:

  • Close Android Studio关闭 Android Studio
  • Go to projects folder ie where the projects are saved (Documents)转到项目文件夹,即保存项目的位置(文档)
  • Rename the desired folder to whatever you want (keep naming conventions)将所需的文件夹重命名为您想要的任何名称(保持命名约定)
  • Open renamed project in Android Studio and clean project在 Android Studio 中打开重命名的项目并清理项目
  • Open app -> java -> right click package name folder containing activity -> select rename and follow prompts打开应用程序 -> java -> 右键单击​​包含活动的包名文件夹 -> 选择重命名并按照提示操作
  • Project should be renamed.项目应该重命名。

Note: There might be a .iml file with the old name.注意:可能有旧名称的.iml文件。 It can be renamed if you want the project to be completely clean.如果您希望项目完全干净,可以重命名它。

Below strategy worked for me:以下策略对我有用:

  1. Close Android Studio关闭Android Studio
  2. Change Android Project root directory name更改 Android 项目根目录名称
  3. Open Android Studio打开安卓工作室
  4. Open the project from Android Studio (Try not to open the project from android studio history but by browsing it )Android Studio打开项目(尽量不要从 android studio 历史记录中打开项目,而是通过浏览它
  5. If settings.gradle contains the below line, change it to the new project name or remove it如果settings.gradle包含以下行,请将其更改为新的项目名称将其删除

    rootProject.name = 'Your project name' rootProject.name = '你的项目名称'

  6. Clean the project and Build it清理项目并构建它

thanks谢谢

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

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