Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 545
Renetik Avatar asked Mar 13 '12 10:03

Renetik


2 Answers

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.

like image 194
Herr Grumps Avatar answered Nov 19 '22 03:11

Herr Grumps


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.

like image 34
Renetik Avatar answered Nov 19 '22 03:11

Renetik