This is the first time I'm using libgdx and I've got one problem. I am confused by the web of dependencies and the number of projects and I'm not sure how and mostly where to add a third party library I want to use. It should work both for desktop and android. How is this done?


2 Answers 2


Ashes999 is right there but I took some extra steps in order for it to work so here they are:

1) Create a libs folder inside the core project's root folder and add whatever JARs you got inside it.

2) In the build.gradle file which is inside the main root folder that contains the various platform projects find where it declares the dependencies of the core project and add this:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')

3) Now you need to refresh your projects for the dependencies to work. An easy way I found to do this is to install this plugin. After you're done right click the projects -> configure -> convert to gradle project. Now that they are gradle projects right click them -> gradle -> refresh all.

4) By now it should work for the desktop but for some reason android will still not recognize the dependencies and crash. What you need to do is right click the android project -> properties -> build path -> "libraries" tab and point it to the jars you placed inside the core/libs folder. After that you also need to go to the "order and export" tab and tick any jars you added. I'm not sure if this is the best way to do it but it works.

  • \$\begingroup\$ Instead of exporting the JARs from the Android project, try exporting them from the core project. \$\endgroup\$
    – ashes999
    Commented Aug 5, 2014 at 13:19
  • \$\begingroup\$ Please mark this as accepted (click the green checkmark) so people know how you solved it. \$\endgroup\$
    – ashes999
    Commented Aug 7, 2014 at 20:57

It depends how you want to do it. libGDX "recently" moved to Gradle, which, among other things, manages dependencies for you. Your options:

Do it the Gradle Way

  • Open up build.gradle for both projects
  • add the right dependency under dependencies

You find the exact string, you need to use Maven Search, then click on the version number, then click on Gradle/Grails.

For example, for JUnit, you would write:

dependencies { compile 'junit:junit:4.12-beta-1' }

Do it the Pre-Gradle Way

  • Make a directory called libs (or lib, Android is particular about this but I can't recall which one) in your projects
  • Download and drop your JAR files within them
  • Add the dependencies (as above for Gradle, to to Eclipse via Java Build Path setup.)
  • \$\begingroup\$ I finally got it to work! :) For the first way though, if I understood how gradle works right, it's better to add it in the core project to be shared or you'd have to duplicate the library in both projects. I'll post exactly what I did in case anyone needs this. \$\endgroup\$
    – user40079
    Commented Aug 5, 2014 at 11:44
  • \$\begingroup\$ I added a comment to your answer. If the DLLs really can be shared, you should add them to the core project and export them so that other projects (desktop, Android, etc.) get them too. \$\endgroup\$
    – ashes999
    Commented Aug 5, 2014 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .