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

18

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.

Stead answered 2/3, 2011 at 12:13 Comment(1)
This solution helped in my case: #9283540 I hope it helps someoneFactitious
S
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.

Stead answered 2/3, 2011 at 12:14 Comment(6)
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.Kantar
+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...Drier
Sometimes Eclipse will remove the reference, restart eclipse and add again, now it should work.Kuhn
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.Likewise
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!Diffract
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.Akkerman
S
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.

Shepard answered 25/7, 2013 at 11:9 Comment(1)
How can I use same library project to another project. If I do so it showing red colour cross symbol.. @KarthikConchitaconchobar
Q
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.

Quaternary answered 9/5, 2012 at 9:35 Comment(2)
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).Whitening
worked for me too. I replaced the referenced project in the same drive (H:) and now it's okBergquist
P
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

Phytopathology answered 22/2, 2012 at 10:58 Comment(1)
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...Hyperkeratosis
P
3

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

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

Prologize answered 2/3, 2011 at 12:13 Comment(0)
T
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).

Tow answered 30/3, 2012 at 13:0 Comment(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.Durarte
M
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

Massicot answered 14/8, 2012 at 8:10 Comment(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)Savitt
T
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.

Timmerman answered 24/8, 2012 at 12:49 Comment(0)
U
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....

Unbolt answered 10/3, 2014 at 7:1 Comment(0)
E
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

Elayneelazaro answered 18/6, 2013 at 16:17 Comment(1)
Creating a new workspace also solved the issue. You also need to clear the projects.Cede
P
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
Pusher answered 8/10, 2014 at 21:55 Comment(0)
T
1

Just restart your eclipse. It's solve my problem

Tsar answered 25/6, 2015 at 12:59 Comment(0)
P
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.

Paravane answered 6/11, 2011 at 8:29 Comment(0)
G
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).

Graaf answered 10/5, 2013 at 14:57 Comment(1)
Also worked for me. Just removed and reimported the projects (as 'existing eclipse project')Perjured
P
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.

Piss answered 11/7, 2013 at 1:34 Comment(0)
R
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").

Rosariorosarium answered 8/7, 2014 at 18:53 Comment(0)
C
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.

Caenogenesis answered 21/7, 2014 at 17:8 Comment(0)
A
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
Arciniega answered 27/8, 2014 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.