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

IntelliJ 2018 CE下Gradle+Java8开发libGDX跨端项目的命令行问题

Hey there, let's break down your libGDX issues step by step and get your setup running smoothly with IntelliJ 2018 CE, Gradle, and Java 8.

1. Fixing the JRE/JDK Path & Missing tools.jar Error

The tools.jar error happens because JRE doesn't include development tools like tools.jar—you need to point Gradle to a full JDK 8 installation instead. Here's how to fix it:

  • First, check which JVM Gradle is using: run ./gradlew -version in your project root. Look for the "JVM" line—if it says "JRE" instead of "JDK", that's the problem.
  • Set JAVA_HOME to JDK 8:
    • On Windows: Open Command Prompt and run set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_XXX (replace XXX with your JDK patch version).
    • On macOS/Linux: Run export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_XXX.jdk/Contents/Home (adjust the path to your actual JDK location).
  • Project-level override: For a more reliable fix, add this line to your project's gradle.properties file:
    org.gradle.java.home=/path/to/your/jdk1.8.0_XXX
    
    This ensures Gradle always uses the correct JDK for this project, regardless of system settings.
2. Troubleshooting gradlew desktop:debug Stuck at ~80%

Stuck builds usually relate to cached dependencies, network issues, or unresponsive tasks. Try these steps:

  • Clean and refresh dependencies: Run ./gradlew clean build --refresh-dependencies to wipe old build artifacts and force Gradle to re-download dependencies. This fixes most cache-corruption issues.
  • Check network connectivity: If the build is stuck downloading dependencies, make sure your network is stable. You can also add a domestic Maven mirror to your project's root build.gradle to speed up downloads (replace the default repositories with something like):
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
        mavenCentral()
        google()
    }
    
  • View detailed logs: Run ./gradlew desktop:debug --info to see exactly which task the build is stuck on. This might reveal if a test is hanging, a resource is locked, or a dependency is failing to resolve.
  • Verify IntelliJ Gradle config: Open IntelliJ, go to File > Settings > Build, Execution, Deployment > Build Tools > Gradle. Make sure "Gradle JVM" is set to your JDK 8 installation (not JRE).
3. Full Setup for libGDX Android & Desktop on IntelliJ 2018 CE

Since your 2017 setup worked, the 2018 upgrade likely changed some default configurations. Here's how to get everything aligned:

Prerequisites

  • Install Java 8 JDK (avoid newer versions—libGDX 1.x has best compatibility with Java 8).
  • In IntelliJ, install the Android SDK via File > Settings > Appearance & Behavior > System Settings > Android SDK. Install at least API level 28 (libGDX 1.9.x recommends this) and the Android Build Tools.

Import & Configure the Project

  1. Import the project: Open IntelliJ, select File > Open, then choose your project's root build.gradle file. Select "Open as Project" and wait for Gradle to sync.
  2. Set language levels:
    • Open File > Project Structure (or press Ctrl+Alt+Shift+S).
    • For all modules (Android, Desktop, etc.), go to Modules > [Module Name] > Sources and set "Language level" to 8 - Lambdas, type annotations etc..
  3. Android module setup:
    • In Project Structure, go to Modules > Android > SDK and select your installed Android SDK.
    • Ensure the "Compile SDK version" matches the API level you installed (e.g., API 28).
  4. Desktop module run configuration:
    • Go to Run > Edit Configurations, click the + button, and select "Application".
    • Set "Main class" to your desktop launcher (e.g., com.yourgame.desktop.DesktopLauncher).
    • Set "Working directory" to $PROJECT_DIR$/assets (this ensures libGDX can find your game assets).
    • Under "JRE", select your JDK 8 installation.

Verify Builds

  • First, test the desktop build via command line: ./gradlew desktop:run. If this works, the core setup is good.
  • Then, run the Android configuration in IntelliJ—make sure you have an emulator or physical device connected, and that the Android SDK is properly configured.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:52:41