使用libgdx与gdx-sqlite调试游戏时出现Program type already present错误
Hey, I’ve dealt with this exact duplicate class error when working with libGDX and gdx-sqlite—here’s how to troubleshoot and fix it step by step:
Check for duplicate dependencies
First, dig into your project’sbuild.gradlefiles (both the Android module and core module). Look for any repeated references to gdx-sqlite: this could mean you’ve added both a local JAR file (from your GitHub download) and a Maven/Gradle dependency entry for the same library. Pick one method (either local JAR or remote dependency) and remove the other.Clean project caches
Android Studio’s cached build files often cause weird duplicate class issues. Do two things:- Run
./gradlew clean(usegradlew cleanon Windows) in your project root to wipe build artifacts. - Go to
File > Invalidate Caches... > Invalidate and Restartto clear Studio’s internal cache.
- Run
Audit your dependency tree
Sometimes other libGDX extensions might pull in gdx-sql related classes indirectly. Run./gradlew [your-android-module-name]:dependencies(replace[your-android-module-name]with something likeandroid) to generate a full dependency tree. Look for multiple entries ofcom.badlogic.gdx:gdx-sqlor similar. If you find duplicates, add anexcluderule to your dependency to remove the redundant one. For example:implementation 'com.example.somelibrary:somelib:1.0' { exclude group: 'com.badlogic.gdx', module: 'gdx-sql' }Verify local library setup
If you’re using the manually downloaded gdx-sqlite library, double-check that you haven’t accidentally added it to multiple modules (like core and Android). The gdx-sqlite setup usually requires adding the core library to your core module and the platform-specific library to your Android module—no duplicates here.Resync your project
After making any changes to build files, click the "Sync Project with Gradle Files" button (the elephant icon) in the top-right corner of Android Studio to ensure all changes are applied.
This error almost always boils down to the same class being included in your build multiple times—so focusing on eliminating those duplicates should get your game running again.
内容的提问来源于stack exchange,提问作者Dusan Lilic

