重构包名称会破坏整个应用程序

发布于 2024-11-17 10:59:35 字数 290 浏览 1 评论 0原文

我正在尝试使用 Eclipse 重构我的包,

org.sheehan.activity

出于

org.sheehan.stocks.activity

某种原因,当我这样做时,我的项目就崩溃了,并且 R 没有重新生成。如何正确重构?

更新: 我更新了 Android 清单以反映更改。 R 仍然没有重新生成。即使在干净之后。编译器抱怨 org.sheehan.activity.R

I am trying to refactor my package using Eclipse

org.sheehan.activity

to

org.sheehan.stocks.activity

For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly?

UPDATE:
I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

云柯 2024-11-24 10:59:35

我通过以下方式解决:

Android Tools > Rename Package Application

I resolved by:

Android Tools > Rename Package Application
樱花落人离去 2024-11-24 10:59:35

如果重命名正确,项目中的所有引用都应该已更新。完成此操作后,通过转到“项目”>“清理您的项目”干净的。这应该可以解决它。

If you renamed properly, all your references across your project should have gotten updated. After doing this, clean your project by going to Project > Clean. This should fix it.

梦途 2024-11-24 10:59:35

修复 eclipse 中缺少对 R 的引用:

  1. Refactor ->重命名`

  2. `

    构建 ->清理

  3. Android 工具 ->修复项目属性

Fixing missing reference to R in eclipse:

  1. Refactor -> Rename`

  2. Build -> Clean

  3. Android Tools -> Fix Project Properties

温柔少女心 2024-11-24 10:59:35

在 Eclipse 包资源管理器中选择项目的基础包,按 F2(重命名),在重命名对话框中:选择所有复选框。:
在此处输入图像描述

应该可以了

select the base package of your project in the eclipse package explorer, press F2 (Rename), in the rename dialog: SELECT ALL the checkboxes.:
enter image description here

That should do it

梦途 2024-11-24 10:59:35

XML 文件中的包名称不会更新。具体来说,您的清单需要了解基础包。

The package name doesn't update in the XML files. Specifically your manifest which needs to know the base package.

鹿港巷口少年归 2024-11-24 10:59:35

对于更高级的导入和重构,从字面上关闭 Eclipse IDE 可能会刷新缓存,从而导致随机错误,例如“结束位置位于文档范围之外”或“曾经有效的现在不再出现错误”。

尝试重命名时应该关闭 Eclipse 的标志是:

  1. 当您导入项目时,进行一些重构(例如尝试更改包名称),然后删除该项目并重试,您将立即看到 R.java 错误当您之前没有这样做时

  2. 当您导入项目 已手动生成具有自定义导入(如“com.ns.proj.R”)的 R.java 文件,并且在预览中看不到名称更新

  3. 询问您是否要“重命名子包”的框被意外选中

  4. “预览>>”中的代码看起来好像之前已经编译过了,而不是用正确的名称替换了黑白代码

  5. 您在清单活动名称中遇到 XML 错误,如下所示

android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="@android:style/Theme.Light.NoTitleBar"

应该是

android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"

太多了,无法一一列举,但这与运动中的“盯着球”一样重要。有些事情很容易忘记,但类似的事情适用于 Dreamweaver 等其他软件程序(例如,当您使用 Dreamweaver“放置”选项而不是使用 FileZilla 进行 FTP 拖动时,您会发现您的域没有在线更新您的更改)。 8 年前,当我刚开始担任开发人员时,我给 Adob​​e 打电话,因为我知道我没有做错任何事。他们说有时执行操作生成的文件会被损坏......换句话说,IDE 也有错误!

一般来说,请在关闭之前关闭 IDE...这可以挽救您的生命!

For more advanced imports and refactors, literally closing the Eclipse IDE can refresh a cache that causes random errors like "End position lies outside document range" or the "what once worked now doesn't hair puller outter errors."

Signs you should close Eclipse when trying to rename things are:

  1. When you import a project, do some refactoring (like trying to change the package name), then delete the project and try again, you will see immediate R.java errors when you didn't before

  2. When you are importing projects that have manually generated R.java files that have custom imports like "com.ns.proj.R" and don't see the name update in Preview

  3. The box that asks if you want to "Rename subpackages" is checked unexpectedly

  4. the code in the "Preview>>" looks as if it's been complied before instead of black and white code with the proper names replaced

  5. you get XML errors in the manifest activity name like this

android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="@android:style/Theme.Light.NoTitleBar"

when it should be

android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"

There are too many to name obviously, however this is as important as "keep your eye on the ball" in sports. Something that is so easy to forget, yet things like these apply to other software programs like Dreamweaver (e.g. when you use the Dreamweaver "Put" option instead of FTP dragging with FileZilla and you notice your domain isn't updating your changes online). I called Adobe when I first started as a developer 8 years ago because I knew I wasn't doing anything wrong. They said sometimes the generated files to perform the action get corrupted...in other words, IDE's have bugs too!

In general, close the IDE before you off yourself...it could save your life!

萌能量女王 2024-11-24 10:59:35

右键单击您的项目,转到

Android Tools > Rename Package Application

“有时,如果 Project >” Clean 不起作用,因此删除项目的 /gen/bin 文件夹。

Right click in your Project, go to

Android Tools > Rename Package Application

Sometimes if Project > Clean doesn´t work, so Delete /gen and /bin folders of your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文