In eclipse, unable to reference an android library

2019-01-02 14:41发布

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.

18条回答
春风洒进眼中
2楼-- · 2019-01-02 15:08

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.

查看更多
一个人的天荒地老
3楼-- · 2019-01-02 15:09

Just restart your eclipse. It's solve my problem

查看更多
有味是清欢
4楼-- · 2019-01-02 15:12

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

查看更多
牵手、夕阳
5楼-- · 2019-01-02 15:13

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

查看更多
梦醉为红颜
6楼-- · 2019-01-02 15:14

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

查看更多
君临天下
7楼-- · 2019-01-02 15:15

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

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

查看更多
登录 后发表回答