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.

1

18 Answers 18

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.

6
  • 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, 2011 at 9: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, 2011 at 3:18
  • 20
    Sometimes Eclipse will remove the reference, restart eclipse and add again, now it should work.
    – Warpzit
    Mar 13, 2012 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. Nov 5, 2012 at 9: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, 2014 at 14:11
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.

1
  • 1
    How can I use same library project to another project. If I do so it showing red colour cross symbol.. @Karthik Feb 13, 2015 at 9:03
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.

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, 2012 at 4:19
  • worked for me too. I replaced the referenced project in the same drive (H:) and now it's ok Mar 3, 2017 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

1
  • 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, 2013 at 17:15
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).

1
  • 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, 2012 at 6:42
3

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

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

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

1
  • +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, 2012 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....

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

1
  • Creating a new workspace also solved the issue. You also need to clear the projects. May 7, 2014 at 21:49
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
1

Just restart your eclipse. It's solve my problem

0
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.

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).

1
  • Also worked for me. Just removed and reimported the projects (as 'existing eclipse project')
    – six5536
    Dec 3, 2013 at 11:14
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.

0
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").

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.