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 -versionin your project root. Look for the "JVM" line—if it says "JRE" instead of "JDK", that's the problem. - Set
JAVA_HOMEto JDK 8:- On Windows: Open Command Prompt and run
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_XXX(replaceXXXwith 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).
- On Windows: Open Command Prompt and run
- Project-level override: For a more reliable fix, add this line to your project's
gradle.propertiesfile:
This ensures Gradle always uses the correct JDK for this project, regardless of system settings.org.gradle.java.home=/path/to/your/jdk1.8.0_XXX
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-dependenciesto 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.gradleto 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 --infoto 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
- Import the project: Open IntelliJ, select
File > Open, then choose your project's rootbuild.gradlefile. Select "Open as Project" and wait for Gradle to sync. - Set language levels:
- Open
File > Project Structure(or pressCtrl+Alt+Shift+S). - For all modules (Android, Desktop, etc.), go to
Modules > [Module Name] > Sourcesand set "Language level" to8 - Lambdas, type annotations etc..
- Open
- Android module setup:
- In Project Structure, go to
Modules > Android > SDKand select your installed Android SDK. - Ensure the "Compile SDK version" matches the API level you installed (e.g., API 28).
- In Project Structure, go to
- 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.
- Go to
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
相关产品推荐
相关产品推荐

