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

14,736

Solution 1

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.

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.

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)

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.

Solution 2

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.

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 any function 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!

Solution 3

  1. Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
  2. Switch to Order and Export tab and uncheck Android Dependencies
  3. Enjoy

Solution 4

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.

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.

Share:
14,736

Related videos on Youtube

Tyler
Author by

Tyler

Updated on June 18, 2022

Comments

  • Tyler
    Tyler almost 2 years

    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?

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

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

    • Matt Ball
      Matt Ball almost 12 years
      What class? Is it a library class that you have not attached the source to?
    • Tyler
      Tyler almost 12 years
      No it is my code that I am writing.
    • Matt Ball
      Matt Ball almost 12 years
      That is strange. I've never seen that behavior before.
    • Tyler
      Tyler almost 12 years
      Edited, when i hit breakpoints.
    • vainolo
      vainolo almost 12 years
      Are you using a java decompiler? maybe this is causing the problem.
    • Dmytro Chyzhykov
      Dmytro Chyzhykov almost 12 years
      Have you seen at this topic? - stackoverflow.com/questions/4553353/…
    • Tyler
      Tyler almost 12 years
      No this is in plain ol Eclipse Debug mode
    • Tyler
      Tyler almost 12 years
      @MattBall it is an external android library that I own
    • BuZZ-dEE
      BuZZ-dEE about 6 years
  • Tyler
    Tyler almost 12 years
    I think youre right because of how android is now packaging external android libraries in jars
  • Sean Aitken
    Sean Aitken over 11 years
    I searched for a long time to find this "Edit source lookup..." option. I finally found it where it's mentioned above in the Debug VIEW!! (The window with the stack and threads listed :)) Thank you!
  • Vince Yuan
    Vince Yuan over 10 years
    Many thanks! Let me write down the detailed steps for those who still don't know how to fix. 1. Begin to debug your project in eclipse. 2. Eclipse menu: Window->Show View->Debug. 3. In Debug view, right click your project name, and select "Edit Source Lookup..." 4. Need not remove 'Default', just click 'Add...' -> Java Project -> The (library) project containing the source files. Make sure the selected project is upper than 'Default' in 'Edit Source Lookup Path' dialog.
  • b-ryce
    b-ryce over 10 years
    This was driving me totally bonkers. But with your advice I finally fixed it. Thanks!
  • Someone Somewhere
    Someone Somewhere over 10 years
    After I made this setting change, Eclipse cleared out the test-projects' run configurations (and it kept trying to launch my library project instead of the test project - and of course libraries can't be run directly). To fix it, I used an old-school technique: exit Eclipse and restart it.
  • dhaag23
    dhaag23 over 10 years
    I've tried all the other suggestions and this is the one that worked for me! Thanks!
  • Amar Magar
    Amar Magar almost 6 years
    Does anyone know the steps for Intellij IDE?