eclipse Android R18 更新后,从调试视图中打开源代码编辑 .class

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11441498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:33:13  来源:igfitidea点击:

Opening source code from debug view edits .class after Android R18 update

javaandroideclipsedebugging

提问by styler1972

When I'm debugging my code in Eclipse, I get annoyed when I open up the editor to find out I cant edit it because I'm actually viewing the source of the .class file. How do I get Eclipse to open up the .java file instead of the .class file when in debug mode?

当我在 Eclipse 中调试我的代码时,当我打开编辑器发现我无法编辑它时我很生气,因为我实际上是在查看 .class 文件的源代码。在调试模式下,如何让 Eclipse 打开 .java 文件而不是 .class 文件?

EDIT: When I hit a breakpoint in mycode, it brings me to MyFile.class, instead of MyFile.java, so I can see mycode but not edit it.

编辑:当我遇到断点我的代码,它带给我MyFile.class,而不是MyFile.java,所以我可以看到我的代码,但不能编辑它。

EDIT: I'm guessing it has somethign to do with Android and ADT R18

编辑:我猜它与 Android 和 ADT R18 有关

回答by styler1972

After I finally found some time and good reason to look into this issue a bit deeper I'll elaborate a bit on Thornbjorn's answer.

在我终于找到一些时间和充分的理由更深入地研究这个问题之后,我将详细说明 Thornbjorn 的回答。

As of lately, Google changed the way your Android projects package your external Android libraries. In ADT R17 (I think) it started packaging the external projects source into .jar files and including them directly into your project in the Android Dependencies or /libs folder.

最近,Google 改变了您的 Android 项目打包外部 Android 库的方式。在 ADT R17(我认为)中,它开始将外部项目源打包到 .jar 文件中,并将它们直接包含到您的项目中的 Android Dependencies 或 /libs 文件夹中。

Now, when the debugger hits a breakpoint, it brings up your source code in the .jar, essentially telling you to edit a .class file. The problem is that this file is read-only and so you have to go find your .java source manually. (Pain)

现在,当调试器遇到断点时,它会在 .jar 中显示您的源代码,实质上是告诉您编辑 .class 文件。问题是该文件是只读的,因此您必须手动查找 .java 源代码。(疼痛)

The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.

修复方法是在调试视图中右键单击项目名称,然后从菜单中选择“编辑源查找...”。从那里,删除默认查找路径。之后,手动添加您的项目引用的关联项目(不是 jars)。这是通过单击添加,选择 Java 项目,然后检查适当的项目来完成的。

回答by Dave

OK, so I hate to be "that guy", given the number of people for whom this worked, but this didn't work at all for me. I mean that the "Edit Source Lookup..." menu item was not in the context menu. I did not miss the instruction to do this in the Debug Perspective (presumably in the Project Explorer in the Debug Perspective). I tried it while the app was running and while the app was suspended. I tried checking the menu for the application's project (presumably what the instructions refer to) and for the library's project. No dice. This is with the latest Eclipse build.

好的,所以我讨厌成为“那个人”,考虑到这对其有效的人数,但这对我来说根本不起作用。我的意思是“编辑源查找...”菜单项不在上下文菜单中。我没有错过在 Debug Perspective 中执行此操作的说明(大概在 Debug Perspective 的 Project Explorer 中)。我在应用程序运行和暂停时尝试了它。我尝试检查应用程序项目的菜单(大概是指令所指的内容)和库项目的菜单。没有骰子。这是最新的 Eclipse 版本。

However, I was able to resolve the issue:

但是,我能够解决这个问题:

  1. Set a breakpoint in either your application or the library you are trying to link source for. You can actually put this anywhere as long as the library you are trying to link source for has a function that will appear on the call stack when the breakpoint is hit.
  2. Start debugging your application.
  3. Navigate your app to hit the breakpoint.
  4. Make sure you are in the Debug perspective.
  5. In the Debug tab (where the call-stack appears), find anyfunction from your library.
  6. Right-click that function. The "Edit Source Lookup..." menu option should be there (close to the bottom).
  7. From here, the instructions are the same as Styler's. Click "Add", select "Java Project" and add your project (or multiple projects).
  8. Before you exit the "Edit Source Lookup..." window, if you are like me, you will see that Eclipse has chosen to add a bunch of stuff to the list that you didn't choose. Some of that stuff (probably under expandable items with names like "Android Private Libraries" may be the jars for the libraries you just added source for. Remove those jars from the list.
  9. Profit!
  1. 在您的应用程序或您尝试链接源的库中设置断点。你实际上可以把它放在任何地方,只要你试图链接源的库有一个函数,当断点被击中时,它会出现在调用堆栈上
  2. 开始调试您的应用程序。
  3. 导航您的应用程序以到达断点。
  4. 确保您处于 Debug 透视图。
  5. 在“调试”选项卡(显示调用堆栈的位置)中,从您的库中查找任何函数。
  6. 右键单击该函数。“编辑源查找...”菜单选项应该在那里(靠近底部)。
  7. 从这里开始,说明与 Styler 相同。单击“添加”,选择“Java 项目”并添加您的项目(或多个项目)。
  8. 在你退出“Edit Source Lookup...”窗口之前,如果你和我一样,你会看到Eclipse已经选择将一堆你没有选择的东西添加到列表中。其中一些东西(可能在名称为“Android Private Libraries”的可扩展项下,可能是您刚刚为其添加源的库的 jar。从列表中删除这些 jar。
  9. 利润!

回答by Sergei

  1. Open main project properties -> Java Build Path -> Projectstab and add there projects the main project depend on.
  2. Switch to Order and Exporttab and uncheck Android Dependencies
  3. Enjoy
  1. 打开main project properties -> Java Build Path -> Projects选项卡并添加主项目所依赖的项目。
  2. 切换到Order and Export选项卡并取消选中Android Dependencies
  3. 享受

回答by Thorbj?rn Ravn Andersen

For some reason Eclipse does not believe that the class file comes from your Java file. This is frequently a malconfigured buildpath, or a jar-file used instead of the project generating the jar file.

出于某种原因,Eclipse 不相信类文件来自您的 Java 文件。这通常是配置错误的构建路径,或者使用 jar 文件而不是生成 jar 文件的项目。

Look in the project manager panel (<->button) to see where Eclipse finds the class file and then figure out why it uses that location instead of your project with the source file.

查看项目管理器面板(<->按钮)以查看 Eclipse 在哪里找到类文件,然后找出为什么它使用该位置而不是您的项目和源文件。