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

2

12

I found this bug http://code.google.com/p/android/issues/detail?id=20731 that is resolved but it did not fix this exactly, but I see in comments that this is mentioned there as problem. Is there some way in eclipse to setup dependencies in project somehow , that I will be able to normally jump to source when I am in eclipse editor ? I tried numerous ways to solve this.

My setup is:

Android project that has Android Library setup in Android>Library

Android Library project that is within workspace and have dependency on Java library project

Java Library project that is within workspace and is opened as class file instead of source !!!

  1. Including java library project through build path normally (this is causing build to fail) [2012-03-13 11:07:21 - Taxicar Driver Android] Dx UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lrensoft/java/collections/GenericIterator; [2012-03-13 11:07:21 - Taxicar Driver Android] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) [2012-03-13 11:07:21 - Taxicar Driver Android] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:163)

  2. Not including , project runs ok , but editor is jumping to library class files.

Note that I have to include Android Library project through build path , even though it runs ok without it (it is enough to set is as dependent android library) , but when I remove it I get also those files as class files :) .

So I think that right way is not including projects through build path at all but how then setup project to jump to source ?

Nowise answered 13/3, 2012 at 10:15 Comment(5)
I seem to have started experiencing this as well - I never used to have this problem. Very frustrating, I have tried everything I can think of to no avail :(Outlive
Pressing F3 in Android project for open declaration in my setup , and that is the same action as command + click. This has to be some bug in ADT Eclipse plugin , I was just trying to find workaround. Or I will try some other IDE . Well there is only one that is comparable.Nowise
You mis-understand my comments, I am not suggest your a solution, just curious is your Android Library Project opened as class file when jump from Android Project, just like the java library project is opened as class file when jump from Android Library Project.Brandybrandyn
Ok, this is bug reported here: code.google.com/p/android/issues/… , star it please :)Nowise
10 months later (of opening date) - ticket still has status "new" :)Singh
N
2

I found solution. I have to create Android library from my java library as well and then include it as android library as well as Java library , Then I have to reorder build path export items so Android "Library Projects” are last . And well not much work, Now even rename refactoring works , with some warning but works :) , Well I am happy developer again.

Nowise answered 20/3, 2012 at 10:2 Comment(0)
C
7

I had a similar problem - Open Declaration command would bring up the .class file instead of the .java file. My problem however was occurring when I would use Open Declaration in my Android app project to goto some source in my Android Library project. By following some instructions from a comment on this blog post Eclipse now takes me to the .java file (instead of the .class file) when I use the Open Declaration command.

The instructions are:

  1. Right click on your project, select Properties
  2. Select Java Build Path page
  3. Select Order and Export tab
  4. 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.

That fixed the goto .java instead of .class file issue for me.

(Unfortunately though, after making these changes, this issue appears (at least it did for me): Could not find Library.apk!)

I then setup my workspace as you describe in your question (Android App depends on Android Library project depends on Java Library project) I find that Open Declaration is always taking me to .java files, so it all appears to be working ok in this respect.

Refactoring

I tried to refactor a method which is defined in a class in the Android Library. A popup with a "problem" of

Binary references to a refactored element have been found. They will not be updated, which may lead to problems if you proceed.

However after pressing Continue the refactoring took place without any issues.

I then tried to refactor a method which is defined in a class in the Java Library. I didn't get any popups this time, and the refactoring worked.

The java library aspect might just work these days because the bugs you guys mentioned have been fixed... (I am using Eclipse 4.2.0 with ADT 20.0.3). I thought I would add this answer however incase it helps someone out with issues of Open Declaration jumping to .class instead of .java file.

Chinaman answered 15/10, 2012 at 8:3 Comment(3)
Hey, thanks for the feedback, I appreciate it! I've made the edit as suggestedChinaman
Still - not fixed : code.google.com/p/android/issues/… - edit : wgare is the question : Android App depends on Android Library project depends on Java Library projectTailwind
This did not work for my simple maven project in eclipse STS. I was trying use sources jar of junit.Manumit
N
2

I found solution. I have to create Android library from my java library as well and then include it as android library as well as Java library , Then I have to reorder build path export items so Android "Library Projects” are last . And well not much work, Now even rename refactoring works , with some warning but works :) , Well I am happy developer again.

Nowise answered 20/3, 2012 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.