Eclipse Android Project, How to Reference Library Within Workspace

Eclipse Android project, how to reference library within workspace?

The classical Eclipse/Java way

Add a (workspace) library

  • Right click the project you want to insert in.
  • Click Properties.
  • Select Java Build Path.
  • Select the Libraries tab.

Now, it depends how you compile your library.
So either do an Add JARs... or an Add Class Folder.
Choose the external variant to use an external source.
That's it.

Add a workspace project

  • Right click the project you want to insert in.
  • Click Properties.
  • Select Java Build Path.
  • Select the Projects tab.

Click Add... on the right side and you are done.

The additional Android way

Two steps are necessary:

  • Mark the project you want to use as library project
  • Reference the marked project

Mark the library project

Right click your project and select Properties.
Select Android on the left and tick the checkbox IsLibrary. Done.

Reference the marked project

Right click your project and select Properties.
Select Android on the left and Add... your marked project. It will be added to the list and is ready to use. Now you are able to access all classes and ressources (e.g. drawables, strings) from the referenced, marked project. Awesome, eh? :)

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

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.

Cannot reference an android library project in Eclipse

To add code as a library, you first need to import it into your Eclipse workspace (right-click your Package Explorer, select 'Import...', 'Android', 'Existing Android code into workspace...'.), and then define it as a 'Library', by selecting 'is library' in that project's properties window.

Can't reference an Android library into my project

I have resolved to issue by removing eclipse, and reinstalling, seems to be a Eclipse bug when previously using 2 workspaces...

According to this question SO Link

What is the recommended way to reference an Android library project in Eclipse

In the package explorer view:

Right click on the library project -> project properties -> android tab

Check: Is Library.

Right click on the Android Project -> project properties -> android tab

Click the "add" button, and select your library project from the list.

To answer you "static question" the difference between and Android library project and a jar'd library is that the android tools automatically fixes resource (xml) references for your project (the generated R file, etc) and then it packages the classes into a .jar file and adds it to your project's apk. So it is included statically.

As to your build path and order and export tabs. The build path is where you can add: .jar files, other projects in your work space, and additional source files to your project. The order/export tab from this is where you select what libraries/class files are going to be statically included with your project's jar file (or apk in the case of Android projects).

How to import an existing Android Library project into Eclipse workspace

Right click on Workspace - > Import -> Existing Android Code Into Workspace -> Library Folder

Note:

To avoid other inconveniences, do this:

1) Once is already in your Workspace, make sure that the project is marked as "Library." Right click on Library -> properties -> Android -> Check Is Library

2) At the time of importing, change the name of the folder. Please, specify something different than just "library". Projects on github usually come that way.

3) Make sure that every file is in the folder. For instance, Eclipse won't import anything if project.properties is not inside the Library folder. In a similar situation, Eclipse could import the project, but it would not create the R.java file if something is missing or there are errors in the layouts of the library.

4) Make sure that all dependencies match with your project. For instance, if certain library needs android-support-v4.jar, make sure that both (project and library) share the same version of the file. Once again properties -> Java Build Path -> Libraries -> Add or remove Jars

5) To make your project dependent of the imported library, Right Click on the project -> properties -> Android -> scroll until the end and add the imported library.

How to add a Library Project to a android project?

  1. File->New->Other
  2. Select Android Project
  3. Select "Create Project from existing source"
  4. Click "Browse..." button and navigate to johannilsson-android-actionbar\actionbar
  5. Finish (Now action bar project in your workspace)
  6. Right-click on your project -> Properties
  7. In Android->Library section click Add
  8. select recently added project -> Ok
  9. that's it!

Now you can use it

Eclipse adding project reference

    By Properties > Android > Add project reference
  • You can only add libraries project as a references.

    Using the other method:  
    By Properties > Java Build Path > Projects tab > Add project reference.
  • You can also add whatever kind of project as a reference. Doesn't matter if it is library project, android, java, C++ or whatever kind project that is in the same workspace of your project.

If you want to add .jar files I recommend you to use the By Properties > Java Build Path > Libraries > Add JARS or Add External JARS.

Also you can copy and paste the .jar file inside of your libs folder in your project. But you have to copy/paste in Eclipse, because in this way, eclipse update the references automatically into your project (in this way, the project know that you added a new library)



Related Topics



Leave a reply



Submit