104

As I was writing up this question I managed to solve it so repeat it here for the benefit of others. Here is the initial problem:

I have created a very simple library project which I want to reference in another project. I have done this previously with no problems so not really sure why it is not working this time. I have:

  1. Flagged the library project via project properties. The default.properties file has this set : android.library=true

  2. In my other project added reference to my library project via project properties. The default.properties file has the reference added as expected ie android.library.reference.1=K:/android_test_ws/applicationRegistrar

  3. The green tick against the referenced library project starts off green and then changes to a red cross.

This implies that there must be something wrong / missing from the library project but I don't know what. My library project on this occasion is MUCH simpler than the previous one I created.

Laurent.B
  • 213
  • 2
  • 14
malcooke
  • 2,906
  • 3
  • 19
  • 15
  • This solution helped in my case: http://stackoverflow.com/questions/9283040/eclipse-android-project-how-to-reference-library-within-workspace I hope it helps someone – Abeer Sul Jan 11 '15 at 16:03

18 Answers18

161

OK Here is the solution which I found when I was looking for the default.properies file of the referencing project (not the library) in my file system. Although the referencing project was in the same eclipse workspace as the library project, the actual files were somewhere else in the file system ie they were'nt in the same parent folder of the library project. As soon as I placed the referencing project in the same physical folder as the library project it all went fine.

I guess that this must be something to do with android using ant underneath the covers.

Edit: The project name needs match the folder name on the file system. What you are seeing in the Project Properties->Android->Library Reference is a relative file system path.

Jason Axelson
  • 4,485
  • 4
  • 48
  • 56
malcooke
  • 2,906
  • 3
  • 19
  • 15
  • 3
    Also want to add that symbolic links aren't okay for this. I had all my projects stored in the same folder as each other in a different location (where I put stuff I want backed up) and then a bunch of symbolic links within my workspace folder to these folders. So they _were_ all in the same folder as each other in both places, however the use of symbolic links messed it all up. Once I loaded the real folder as my base workspace it was all fine. – Zulaxia Apr 25 '11 at 09:00
  • 7
    +1 For articulating this HORRIBLE behavior of the Eclipse/ADT combo. Just FYI, even placing both projects in the same physical folder doesn't help **if that folder happens to be on a Samba share**. Ugrrr... – an00b Jun 15 '11 at 03:18
  • 20
    Sometimes Eclipse will remove the reference, restart eclipse and add again, now it should work. – Warpzit Mar 13 '12 at 11:50
  • This was a problem to my projects belonging and located in the same workspace. Imported the project in the same workspace as the library and everything worked fine. Thanks for the answer. – Jayshil Dave Nov 05 '12 at 09:19
  • Check that your workspace and library are in the same folder location. Made the mistake of redownloading ADT and created a project under C:\users workspace as opposed to my actual workspace. Needless to say, check again that your project AND your library are in the same working directory! – Garbit Jan 20 '14 at 14:11
  • Had the same issue, removing the project and re-importing the project and copying it into the workspace fixed it. Such a stupid issue, thanks malcooke for this fix. – CodyEngel Oct 02 '14 at 02:56
11

Make Sure both the projects are present in same work space. To Do it, while importing the projects make sure "copy project into work space" check box is checked.

Karthik Dheeraj
  • 1,039
  • 1
  • 13
  • 25
10

the same problem will occur if your library project is in different partition from your current workspace. I have the same problem just now. My git source is in C: and I just move my workspace to D: and everything start to collapse.

user791129
  • 111
  • 1
  • 2
  • 4
    If the main and library projects are on _different drives_, it seems that Eclipse can't resolve the Reference path from absolute to relative, and Eclipse is not happy about it (green tick turns into red cross). – Pang Dec 24 '12 at 04:19
  • worked for me too. I replaced the referenced project in the same drive (H:) and now it's ok – Tobia Zambon Mar 03 '17 at 17:25
4

Simplest way to get the library paths paths correct is to use the GUI from Eclipse to add the library as shown in the following screenshot and let Eclipse take care of putting the correct relative paths in project.properties. Its a common setup to have your library projects hosted at directories vastly different than your main projects that uses the library. This method will work if the "libary project" and the project using it are in the same eclipse "workspace" (they "need not" be in same parent folder): enter image description here

Nilesh Pawar
  • 3,895
  • 3
  • 21
  • 19
  • 4
    The problem is because the library and project are on different drives/partitions...see the bug listings above. Yours is fine because your library path shows relative paths instead of DOS full paths... – kenyee Jul 12 '13 at 17:15
3

This bug is referenced several times here 27199, 35786, 36460 & 38052

Maybe by voting for them, it will be fixed one day...

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
Laurent.B
  • 213
  • 2
  • 14
3

Please ensure that the library project is marked as "Is Library" - right click on the library project - properties - Android - mark the "Is Library" checkbox - in project.properties of the library project you should have a new entry:"android.library=true. Now add it into the project you want as described in the post below.(the post with image integrated - from Nilesh Pawar).

Alexandru Circus
  • 5,478
  • 7
  • 52
  • 89
  • 1
    This worked just fine for me. The confusing part is I think the location of this 'Is Library' checkbox. It's not intuitive that this is actually selecting the target of the current app/library build and not an option switch for the libraries to be included. – EtienneSky May 16 '12 at 06:42
2

Yet another observation on the same issue.

For me the two projects where on the same parent folder, and were both local inside the workspace. Even then the issue was still happening.

The I edited the "project.properties" file and put the absolute path(with forward slashes '/' for seperator) of the library project. Saved and closed it. Then went to the project properties dialog, removed the library(which was still showing the cross icon but with abs path) and added it back as usual. Surprisingly the issue is resolved, and the project compiles and runs.

This is really strange and must be a bug with the ADT. I am using ADT version 20.0.2

CuriousChettai
  • 1,862
  • 1
  • 12
  • 10
  • +1. Faced this issue while switching libraries with same names. Looks like eclipse(or ADT) trying to reference to the old one and fails. Eclipse restart helps. (Ubuntu 12.04, Eclipse Indigo, ADT 21.0.0) – Luten Nov 19 '12 at 11:05
2

when developer referencing the facebook or any other library project then first of all clean the project from eclipse->project->clean project. that want allow the error of red cross in referencing screen.

2

For me, I just restart the eclipse and the added library works fine.

I mean first time it showing red marks after adding the library project. Though eclipse main project and library project are in same workspace folder and no resources files are in outside of the project folder.

So, you can try with to restart your eclipse. Happy coding....

Md Sufi Khan
  • 1,751
  • 1
  • 14
  • 19
1

Workaround for me was to

  1. Create a new workspace
  2. Import Library Project in that workspace
  3. Import The desired project in that workspace
  4. Having both project and library project the same target Android OS version
  5. Reference library project in my project

solved my problem

QAMAR
  • 2,684
  • 22
  • 28
1

i had the same problem there when i try to change my workspace so this my solution:

  1. import and copy all project data including library project into workspace
  2. delete the old project reference by Right-click on the project-->Properties-->Android-->Library, and select corrupted library(so that waht i call it) and choose Remove
  3. clean project first (to refresh ur project properties)
  4. go to library project Properties-->Android-->Library and check the is library if it does'nt click Apply then OK
  5. if the library project is library is already checked, first Unchecked it then Clean the library project after that do the Step 4 again
  6. go to project that u want the library are in then Right-click on the project-->Properties-->Android-->Library, Add then choose the library project (it should be there) and click Apply then OK
  7. if still doesn't appear clean the project once more time and that should do
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
ibrahim saputra
  • 407
  • 6
  • 12
1

Just restart your eclipse. It's solve my problem

Manisha Patel
  • 409
  • 1
  • 4
  • 12
0

FYI,

What worked for me was to delete the 'library' projects (the actual projects) from my workspace (without deleting the files), and then re-importing them using the wizard (import existing android project from source code).

JRun
  • 3,328
  • 6
  • 27
  • 41
0

Thanks for posting the question. I had exactly the same problem while integrating Facebook with my Android application. I fixed the issue by moving my development project to the same Windows drive in which library project was located. Somehow Eclipse is unable to read the library project's location properly from default.properties file if it is in a different drive.

Girish K Gupta
  • 190
  • 1
  • 7
0

Similar to Sufi Khan's post I also solved this issue with a reboot. My case differed in that when I first accessed Properties->Android and added the library I got a lovely green checkmark. When I closed the dialog Eclipse was still showing class-not-found type errors. When I checked the properties again I saw the red X. But Mr. Kahn's solution (delete the bad lib, restart Eclipse, add the lib again) worked fine.

I'm using the 0702 version of the ADT bundle (starts with "cluster", rhymes with "duck").

William T. Mallard
  • 1,562
  • 2
  • 25
  • 33
0

I followed the accepted answer but also had to make sure my "project.properties" file was readable.

If the file is readonly (checked into source control) eclipse will not edit it. Adding the library reference will succeed, but the change won't be persisted after hitting OK.

If closing the preferences window and reopening in again removes the library you just added, this may be your solution.

repkap11
  • 757
  • 7
  • 9
0

In case your library project still doesn't show up try adding library flag in your library project properties

Add android.library=true

project.properties

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
android.library=true
HimalayanCoder
  • 9,630
  • 6
  • 59
  • 60
0

When you have a look at the reference-path before and after, it comes from i.e. "C:/workspace/mylib" and goes to "../../mylib" when copied to the correct location, quite interesting.

Sebastian
  • 221
  • 1
  • 3
  • 9