You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

libGDX新项目创建失败:无法确定Java版本'9.0.1'求助

Fixing libGDX Project Generation Failure & Upgrading Gradle Version

Hey there! Let's work through this issue together—you’re spot-on that the Java version error and Gradle version are tied together here. Old Gradle versions don’t play nice with Java 9+, which is exactly why you’re seeing that Could not determine java version '9.0.1' error. Here’s how to fix this and get libGDX running with the latest Gradle:

First: Address the Java Version Recognition Issue

The root of the error is that the default Gradle version used by older libGDX setups doesn’t support Java 9. You’ve got two paths here:

  • Switch to Java 8 (it’s the most compatible with older libGDX versions, if you don’t need Java 9+ features)
  • Upgrade Gradle to a version that supports Java 9+ (which is what you’re asking for—let’s focus on this)

Second: Upgrade Gradle for Your libGDX Project

If you’re still creating the project, use the libGDX generator (web or desktop app) to set a newer Gradle version upfront:

  • Look for the Advanced section (usually tucked at the bottom or side of the generator UI)
  • In the Gradle Version field, enter the latest stable Gradle version (aim for a version that supports your Java 9 installation, like Gradle 6.0+ for Java 9)
  • Also, set the Java Version dropdown to match your installed JDK (9 in your case) to ensure compatibility

Option 2: Manually Update an Existing Failed Project

If you already generated the project and hit the error, tweak these files in your project folder:

  1. gradle/wrapper/gradle-wrapper.properties (root directory)
    • Update the distributionUrl to point to the latest Gradle binary. For example:
      distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
      
  2. build.gradle (root directory)
    • Find the buildscript block, and update the libGDX Gradle plugin classpath to a version compatible with your new Gradle. For example, using the latest libGDX release:
      buildscript {
          repositories {
              mavenCentral()
          }
          dependencies {
              classpath "com.badlogicgames.gdx:gdx-tools:1.12.1"
          }
      }
      
    • Also, ensure your source/target compatibility matches your Java version:
      allprojects {
          apply plugin: "eclipse"
          apply plugin: "idea"
      
          version = '1.0'
          ext {
              appName = "YourProjectName"
              gdxVersion = '1.12.1'
          }
          repositories {
              mavenCentral()
              maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
              maven { url "https://oss.sonatype.org/content/repositories/releases/" }
          }
          sourceCompatibility = 1.9
          targetCompatibility = 1.9
      }
      
  3. Sync the Project
    • Open the project in Android Studio, click the "Sync Project with Gradle Files" button (the elephant icon in the toolbar), and wait for the sync to complete.

Quick Extra Checks

  • Make sure your libGDX dependency versions are up-to-date—newer versions are built to support modern Gradle and Java releases
  • Double-check Android Studio’s Project Structure (File > Project Structure) to confirm the SDK and Language Level are set to Java 9, matching your installed JDK

内容的提问来源于stack exchange,提问作者Thomas Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:13:26