简体   繁体   English

如何用AndroidStudio删除Android软件包名称的一部分?

[英]How to remove parts of an android package name with AndroidStudio?

I have an android project with a package name like com.example.alexander.app and I want to change this to a name containing only three parts, like com.alexapps.firstapp . 我有一个包含com.example.alexander.app等软件包名称的android项目,我想将其更改为只包含三个部分的名称,例如com.alexapps.firstapp However, after searching several sites, I still have no idea how to do that in AndroidStudio (2.1.3). 然而,在搜索了几个网站后,我仍然不知道如何在AndroidStudio(2.1.3)中这样做。

I found the following answer, which do not fully answer my question: 我找到了以下答案,但没有完全回答我的问题:

  • Answer 1 requires the file R.java which I cannot find 答案1需要我找不到的文件R.java
  • Answer 2 looked very good by using methods in AndroidStudio. 通过使用AndroidStudio中的方法, 答案2看起来非常好。 Unfortunately, even after cleaning and rebuilding the project, the package name was not changed on my single activity. 不幸的是,即使在清理和重建项目之后,我的单个活动的包名也没有改变。
  • Answer 3 : I searched for the string, and found more than 1000 hints!! 答案3 :我搜索了字符串,发现了1000多个提示! Therefore I have not continued with this solution to replace more than 1000 hits, as this does not sound right. 因此,我没有继续使用此解决方案来替换超过1000次点击,因为这听起来不对。 I have only 1 (one!) single activity in this test app... 我在这个测试应用程序中只有1个(一个!)单个活动...
  • Answer 4 : Very good answer, but only useful if you want to change each of the package name parts (and neither increasing nor decreasing the number of parts in the package name). 答案4 :非常好的答案,但仅在您想要更改每个包名称部分时才有用(并且既不增加也不减少包名称中的部件数量)。

So is there a way to remove a part of a package name with AndroidStudio? 那么有没有办法用AndroidStudio删除包名的一部分?

The easiest thing to do is right click the folder/package, and refactor. 最简单的方法是右键单击文件夹/包,然后重构。 This however i think is limited to the final folder, and does not remove a hierarchy. 但是我认为这仅限于最终文件夹,并且不会删除层次结构。

So the solution in this scenario, is to 因此,在这种情况下的解决方案是

  1. create a new folder 新建一个文件夹
  2. move all the folders/files into it. 将所有文件夹/文件移入其中。 (this should initate a refactor on each file) (这应该在每个文件上启动一个重构)
  3. Rename any references to your activities etc in the manifest to the correct package names (it should have done this for you) 将清单中对您的活动等的任何引用重命名为正确的包名称(它应该为您完成此操作)
  4. Clean and rebuild (to fix the R file) 清理并重建(修复R文件)

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

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