33

Current setup:

  • MainProject which is a Library Project

  • BranchProject which is a new projects and has MainProject as a Reference

Whenever I debug and a file from MainProject is on focus (actually BranchProject has only graphic and xml layout changes) the Debug window opens a .class file which is read only. I want it to open the .java file so I can edit it directly.

Alin
  • 14,809
  • 40
  • 129
  • 218
  • possible duplicate of [Opening source code from debug view edits .class after Android R18 update](http://stackoverflow.com/questions/11441498/opening-source-code-from-debug-view-edits-class-after-android-r18-update) – Kristopher Johnson Sep 18 '13 at 16:49
  • Possible duplicate of [eclipse > java > open linked resources sources (.java instead of .class )?](https://stackoverflow.com/questions/8603292/eclipse-java-open-linked-resources-sources-java-instead-of-class) – BuZZ-dEE Apr 19 '18 at 11:09

9 Answers9

60

Skyler's answer from this post worked for me: Opening source code from debug view edits .class after Android R18 update

Here is a summary: 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.

Community
  • 1
  • 1
Steven
  • 615
  • 6
  • 4
  • 3
    Just in case someone could not find "Edit Source Lookup", It comes when you are debugging and it shows stack trace, where you see options for "terminate", "relaunch" etc. – peeyush Mar 19 '15 at 18:28
  • 4
    You can also go to "Debug configurations" and select the "Source" tab, then you can see the "Source Lookup Path" – maxivis Jan 20 '16 at 15:05
6

When you're using a Library project one of the things you're in fact doing is compiling your Library project into a jar and then referencing that jar in your calling Project.

If you right click the Project, and select "Configure Build Path" you'll see a tab called "Libraries", if you look inside "Android Dependencies" you'll notice a list of jar's corresponding to your Library projects.

These jars are expandable, showing you that they have a slot for a source attachment. Usually this would be editable allowing you to directly link the source but in terms of ADT these are already filled and are uneditable.

When debugging these files you're linked to a read-only class file with this attached source. This is because you're not running against source files directly, you're running against a pre-compiled class file. Until the ADT team get this functionality in place, you're pretty much forced to jump to the direct source code and rebuild everything.

EDIT

See @Steven linked answer :)

Graeme
  • 25,714
  • 24
  • 124
  • 186
1

I faced the same issue while debugging the a .java file using Eclipse IDE. As per my understanding this issue comes when we put the xyz.class file of xyz.java file or JAR at the project build path. Delete the .class or JAR file from the project class path and rerun .java file in the debug mode. This time you see a source not found window. Click on "Source not found" button and check "Find duplicates..." at the bottom of the window. Done your problem is solved :)

selva
  • 1,175
  • 1
  • 19
  • 39
1

The problem is that the class file is preferred over the java (by default), here is how you can change that for Eclipse (tested on NEON 2):

  1. Right-click on the Project in the Project-Explorer, click Properties
  2. On the new window select: Run/Debug Settings
  3. Create a new configuration (or duplicate another one)
  4. Select the new config and click Edit...
  5. Go to the tab Source
  6. Select the Default and Remove
  7. Create a new path with Add..., select Java Library, then JRE System Library
  8. Create a new path with Add..., select the location where the sourcecode is by Workspace folder (if it is a project in the same workspace) or File System directory (it it is not)
ataraxis
  • 1,257
  • 1
  • 15
  • 30
0

I think this depends on, how you set up the dependency in eclipse. You should set up your BranchProject to depend on the source-Files of your MainProject. If you depend on compiles Class-Files is obvious that the debugger opens the class files, because it does not know about the source files.

Simulant
  • 19,190
  • 8
  • 63
  • 98
0

I found a good solution for me here:

Using Android library in eclipse and jumping to class files instead of source file that is within eclipse workspace

Simply, select each library project your project depends on, and use Top or Up to move it above the projects outputs. Eg. move all library projects to the top.

Community
  • 1
  • 1
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
0
  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
Sergei Krivonos
  • 4,217
  • 3
  • 39
  • 54
0

If you tried all above hints and it still doesn't work try this solution, it worked form me:

  1. Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path...
  2. Select tab Order and Export
  3. select library that you can't reach code and then click on button Bottom
  4. Then click on Apply and Close

hope this can help you

AntimoV
  • 51
  • 1
  • 5
0

Most of the time it happens when specific source folder are not added in build path Sources tab.

Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path -> Source Tab

Add the source folder if your project source folder is not there. Select Add folder -> select your project source folder specifically. Eg: project_name/src . Then Apply it and restart server.

Mathi
  • 1
  • 1
  • 4