10

I am trying to add a Library to an existing project inside eclipse. I am keeping the Project Folder itself and the Library Folder in a folder marked "ANDROID" on my desktop. When I try to Import > Existing Code into Workspace > Select "ANDROID".. the only project that gets added is the App itself and NOT the library. I even try to add the library on its own and it will show up on the import list but will not have a "ticked box" with the option of "Finish". I even right clicked my App - Properties > Android > and noticed that the library is there with a red "X" and does not allow me to search for a new library. What am I doing wrong? This Identical App and library is working with the same version of eclipse for a friend and not me.

Divya Jain
  • 393
  • 1
  • 6
  • 22
Taylor
  • 101
  • 1
  • 1
  • 3

4 Answers4

23

Make sure that the libraries and the project are at the same place, i.e.

  1. Copy the libraries in the same folder as your project
  2. Import the libraries (file > Import > Existing Project in workspace)
  3. Open properties of library > Android and select Is Library
  4. Open project properties > Android > Add (library)
  5. Select the library
  6. save the properties

If this does not work for you copy the jar files from its lib folder and paste it in the projects lib. This should only be done if the above method doesn't work

gustavohenke
  • 40,997
  • 14
  • 121
  • 129
Umar Ahmad
  • 410
  • 4
  • 15
  • 7
    `Make sure that the libraries and the project are at the same place` is correct answer for me. – user1156041 Sep 05 '13 at 04:48
  • 6
    If your Eclipse still does not store your added library location (you select it and it is green check mark, but when you open it back it is a red cross). Just restart it! – demosten Dec 04 '13 at 00:26
  • I have my projects (including library projects) in a folder outside the main Eclipse folder. While copying a project within Eclipse, I carelessly accepted the default location. This led to exactly the behavior described in the OP. The fix was to move the project to the same external folder as the library it was using, where it should have gone in the first place, just as you recommend here. I did have to restart Eclipse before I could successfully add the library project in Project/Properties/Android. – Carl Aug 09 '14 at 13:22
  • Just to further clarify what has been said (for those, who like me, also take awhile to understand things) make sure that the library and your project are in the same directory folder. For example, they should both be in the "workspace" folder, or in your "git" folder. If one is in the "workspace" folder, while the other is in the "git" folder, you'll get an error. Hope this helps. Thank you. – masarapmabuhay Mar 28 '16 at 06:11
3

Import Library project in eclipse . Then right click on project and go to properties->Android (Menu on left side) --> At the bottom(below project build target) you will see a check box named is Library Check that box. Now you've made your project a library .

Then in your orignal project where you want to add library go again to to properties->Android (Menu on left side) --> At the bottom(below project build target) Click add button and you will find that library project visible.

Jan
  • 859
  • 7
  • 30
  • The problem I am having is the only way it will allow me to add my "Library" to the workspace is if i import it as GENERAL > PROJECT. When I should be importing the library as "USE EXISTING CODE" Once i go to PROPERTIES > ANDROID > LIBRARY PROJECT LIST. There is a red "X" and it simply wont let me add a new one, nor will it turn green once ticking the "is library" box. Its as if eclipse will not recognize the library as a library or the path is wrong. The only reason im so confused is like i said. I have a friend with the identical files, SDK API levels and eclipse version as me with no issues – Taylor Feb 23 '13 at 17:46
  • Basically my first step is getting the library into the workspace as "USE EXISTING CODE". Everytime i try to.. it will not allow me to press "FINISH" and add the library to the workspace. So without being able to add it to the workspace i cant even begin to try and connect it with the app project. – Taylor Feb 23 '13 at 23:08
  • Hmm... is your package is checked when you import or does it give any error on top ? – Jan Feb 24 '13 at 11:51
  • When i try to import the library to the workspace i it will not allow me to "finish" and it says " Select a directory to search for existing Android projects" at the top with a red X. I am storing both the main app project and the library in the same folder together. I have no idea why eclipse will not accept it and let me add it to the workspace – Taylor Feb 24 '13 at 22:33
  • add me on skype : janshair.khan1 . Have a teamviewer session with me then i will tell you . You must be getting error that package already exist. – Jan Feb 25 '13 at 04:53
0

This happens when you import the project from some location. If we import some project then it doesn't refer to the supporting library of that workspace. So always check the check box( copy projects to workspace) Go to file>import project>browse>select a project>Check the copy project into workspace. Hope it solve the issue.

0

A late answer, although I thought of giving an in-depth answer to this question.

  1. First switch your folder structure from Android to Project.

enter image description here

  1. Now search for the libs folder inside app - build folder.

enter image description here

  1. Once you have pasted the .jar file inside libs folder. Right click on the jar file and at end click on Add as library. This will take care of adding compile files('libs/library_name.jar') in build.gradle

enter image description here

Now you can start using the library in your project.

capt.swag
  • 10,335
  • 2
  • 41
  • 41