运行App报错:未指定JDK,Android Studio 3.0.1配置JDK9仍无法运行求助
Hey there, let's work through this frustrating issue you're hitting. I've dealt with similar problems before, and the root cause here is almost always a compatibility mismatch or a hidden configuration hiccup. Let's break down the solutions step by step:
1. Address the core compatibility issue first
Android Studio 3.0.1 does not officially support JDK 9 — it’s built to work best with JDK 8. The module system and underlying changes in JDK 9 clash with the older tooling in AS 3.0.1, which is likely why your setup isn’t working even with correct environment variables.
My top recommendation: Downgrade to JDK 8. It’s the most stable and fully supported version for this AS release. Once you install JDK 8, update your JAVA_HOME, JDK_HOME, and Path variables to point to the JDK 8 directory instead of JDK 9.
2. Verify your environment variables are actually active
Sometimes we set variables but forget to restart our system or Android Studio, so the changes don’t take effect. Let’s confirm:
- Open a terminal (Command Prompt on Windows, Terminal on Mac/Linux)
- Run
java -version— this should show JDK 8 once you’ve downgraded (or your intended JDK version) - Run
echo %JAVA_HOME%(Windows) orecho $JAVA_HOME(Mac/Linux) — this should output the full path to your JDK installation directory
If either command shows the wrong version/path, double-check your environment variable settings, save them, restart your computer, and re-test.
3. Check Android Studio’s global JDK settings (not just the project)
You’ve set the JDK in your project structure, but AS has a global setting that might be overriding this:
- On Windows/Linux: Go to
File > Other Settings > Default Project Structure - On Mac: Go to
Android Studio > Settings > Build, Execution, Deployment > Build Tools > Gradle - Under
Gradle JDK, select the path to your JDK 8 installation. Make sure it’s not pointing to JDK 9 anymore.
Alternatively, you can force Gradle to use the correct JDK by editing your project’s root gradle.properties file. Add this line (replace the path with your actual JDK 8 directory):
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_XXX.jdk/Contents/Home
4. Clear Android Studio’s cache and restart
Corrupted cache can sometimes prevent configuration changes from being applied. Let’s fix that:
- Go to
File > Invalidate Caches / Restart - Select
Invalidate and Restart— this will clear the cache and reboot AS, forcing it to load your updated JDK settings.
5. (Optional) If you really want to stick with JDK 9 (not recommended)
If you insist on using JDK 9, you’ll need to upgrade your Gradle version to at least 4.3 (since older Gradle versions don’t support JDK 9). However, Android Studio 3.0.1 may not play nicely with newer Gradle versions, so this path is riskier. You’d need to:
- Update the
distributionUrlin your project’sgradle/wrapper/gradle-wrapper.propertiesto point to Gradle 4.3 or higher (e.g.,https://services.gradle.org/distributions/gradle-4.3-all.zip) - Ensure your app’s
build.gradleuses a compatible Android Gradle Plugin version (AS 3.0.1 uses plugin version 3.0.1, which should work with Gradle 4.3, but no guarantees)
But again, downgrading to JDK 8 is the far more reliable solution here.
内容的提问来源于stack exchange,提问作者Karim Alaa

