Android Studio: package com.badlogic.gdx does not exist

I tried migrating my project to Android Studio and somehow in the process I messed up some settings I guess.
Now when I import my project i get an error:

package com.badlogic.gdx. etc does not exist & it sums up all the missing packages.

I tried have gradle reimport the necessary dependencies as suggested in this stackoverflow post:

But it didn’t work.

How do i get my project running again?

It could be handy to make sure you have the latest LibGDX version / project creation tool and just create a new project via the GUI tool and then move your source code into the new project. The project creation tool is quite a bit more stable at this point. All dependencies like LibGDX or RoboVM is downloaded automatically via the Gradle config files. Usually from a Maven repo.

Sometimes the LibGDX project creation tools are behind the latest Android Studio Gradle versions and such in the build scripts the GDX tool creates. Often it just requires a couple of changes to the main build.gradle script and then things work right away.

It’s hard to help without much more info on your side.

well thats good to know already.
I’ll probably just try to create a new liBgdx project and migrate my files manually then i guess.

The import took care of all the depencies exept for the libGDX related libraries and thus wherever in my code i was calling libgdx classes I get an error now.
I assume i can also manually download the jar’s and add them to my build path.
Just need to find out how to do that.

You should figure out the Gradle configuration issues as LibGDX will be pulled automatically from Maven and you’ll update LibGDX versions used via the Gradle build config files as well. I am assuming without more info that the problem you are facing regards a mismatch in the Gradle config files the LibGDX project creator is outputting and the latest Android Studio Gradle / build setup.

Here is how you can verify which Gradle build number you should use. First create a normal Android app in Android Studio. This will be your reference, so that you can verify the Gradle config information. You’ll want to look at the top level build.gradle file under your main project directory. The very top of it should look like this:


buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

Take note of the classpatch dependency for gradle version number; above this is “0.12.+”

Now create a LibGDX project and open the build.gradle file in the parent directory.

It may look like this:


buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        classpath 'com.github.jtakakura:gradle-robovm-plugin:0.0.10'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = 'MyGame'
        gdxVersion = '1.2.0'
        roboVMVersion = '0.0.14'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

If the top Gradle version number is different than the normal Android app you created previously then copy the version number from the normal Android app to the GDX build.gradle file. IE change “0.10.+” to “0.12.+”

Also when you first open up an Android studio project navigate to the directory and click on the top level build.gradle file instead of the top level parent directory.

To resynch the Gradle build in Android Studio you will either be prompted automatically when you make changes to the Gradle build files or what is handy is to kick off updating the Gradle build manually. You do this by selecting from the top Android Studio menu: Tools -> Android -> Sync Project with Gradle files

If your gradle config is correct and in line with the Android Studio versions then Gradle will automatically pull down LibGDX and all dependencies such as RoboVM.

Don’t manually include LibGDX as jar files as that will just complicate things and is not the way to set up a Gradle project especially since LibGDX is configured to pull from Maven repos automatically.

When you need to update your version of LibGDX you update the “gdxVersion” and “roboVMVersion” and then hit the sync project w/ gradle files option and the latest versions will be pulled down.

Again, without having more details on what you are facing this is my assumption of what might be holding you up. Gradle take a bit of time to wrap your head around, but is well worth understanding because it is a powerful build system that both Android Studio and LibGDX uses. Let me know if this helps!

Thanks for the information. Appreciate it. Haven’t been able to get to it today, but gonna look at it first thing in the morning & will let you know if it worked.

It seems to be one big mess.

The build.gradle file after i had exported it from eclipse and tried to import in AS now only had a few lines only stating the to-use gradle version (??).

So i tried and copy paste all the info from my gradle.build file from a backup when i was using eclipse, but that didnt work out too.
Now if i am syncing my gradle project i get this issue:

  • project with path ':desktop’could not be found in project

my projects location has all the different project locations though (desktop, core, android…)

Althoug I would like to understand how to solve these issues I guess most time efficient will probably just to create a new LibGDX project, import it into AS and copy/paste all my classes and assets from my project into the new AS project

Yes, I thought we were talking about fresh projects. ::slight_smile: That is definitely necessary for the new LibGDX build system in regard to the setup of the Gradle build, file structure, etc. I wouldn’t trust AS to import Eclipse projects correctly let alone a LibGDX project.

If you have a fresh project created from the most recent LibGDX project creator GUI copy over your old code & assets as applicable. Then you may want to watch out for the small disjoint I mentioned above that can happen when you constantly update AS which may bump the Gradle versions supported or other small changes required to the parent build.gradle file.