Home » Android » In eclipse, unable to reference an android library project in another android project

In eclipse, unable to reference an android library project in another android project

Posted by: admin March 11, 2020 Leave a comment

Questions:

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.

How to&Answers:

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.

Answer:

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.

Answer:

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.

Answer:

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

Answer:

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

Answer:

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

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

Answer:

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

Answer:

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.

Answer:

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

Answer:

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

Answer:

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

Answer:

Just restart your eclipse. It’s solve my problem

Answer:

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.

Answer:

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

Answer:

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.

Answer:

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

Answer:

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.

Answer:

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