Can't change JDK to 7

Answered

I'm trying to migrate an android project from Idea structure to Gradle. I have got to the point where I can build the project from the command line with gradlew, but in Idea I get this error:

compileSdkVersion android-23 requires compiling with JDK 7
Download JDK 7
Select a JDK from the File System
Open build.gradle File

If I click on the "Select a JDK from the File System" link it takes me to the Project Structure dialog where the JDK location has a path to Java 1.6. If I change this to the path to Java 1.7 and click OK I get the same error. Going back to the dialog I see that the path has reverted to Java 1.6!

Any ideas?

13 comments
Comment actions Permalink

Update - this was using Idea 15. I switched back to Idea 14 and the same project built without any problem, without changing anything. Looks like another Idea 15 bug.

0
Comment actions Permalink

Further update - the same project works happily in Android Studio.

0
Comment actions Permalink

Do you have Java 7 JSDK defined in IntelliJ IDEA? Does it happen with any Android Gradle project? If so, please attach a sample project that will reproduce it. What OS do you use? What JDK is used to run IntelliJ IDEA?

Settings to double check:

0
Comment actions Permalink

It happens with a newly created project - it appears to be any project that uses Android API 23.. Zipped copy of a sample project here:

http://www.sr20.org/test2.zip

OS is OSX 10.10.5. I don't know what JDK Idea is running under, but my default is 1.7.0_51. Setting JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home and running Idea from the command line makes no difference. All the paths as per your screenshots are correct - see below. Clicking the "Select a JDK " link takes me to a settings window which has a 1.6 JDK - but any changes to this revert after saving. I cannot find a way to navigate to this settings pane other than clicking the error message.

Running gradlew from the command line in the project directory succeeds:

~/dev/projects/Test2 % gradlew assembleDebug
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE

...

:app:packageDebug
:app:zipalignDebug
:app:assembleDebug
BUILD SUCCESSFUL
Total time: 44.87 secs

0
Comment actions Permalink

It looks like some leftover specific to Android Studio. I'll ask the responsible developer to have a look. Please also provide idea.log (https://intellij-support.jetbrains.com/hc/articles/207241085). JDK that is used to run IDEA can be changed per https://intellij-support.jetbrains.com/hc/articles/206544879.

0
Comment actions Permalink

I have the log - what's the best way to send to you? I don't want to post it in a publicly viewable place.

 

0
Comment actions Permalink

Zip the logs folder and upload it at http://uploads.jetbrains.com/, tell us the file name.

0
Comment actions Permalink

Uploaded as jdk7_issue.zip

0
Comment actions Permalink

You've missed the screenshot showing Gradle JVM (the last in my answer). Could you please provide it?

0
Comment actions Permalink

There seems to be an issue with the code that selects SDK from the list. You have both 1.6 and 1.7 defined and it selects 1.6 from Android API 7 Platform (that is the first Android SDK in the list). You can try changing Java version associated with Android API 7 Platform from 1.6 to 1.7 and see if it helps.

0
Comment actions Permalink

I deleted the Java 1.6 from the list of SDKs and that made the problem go away. I don't have any particular need for the older Android APIs so that's working ok for me now.

0
Comment actions Permalink

Thanks for the information. We'll add SDK configuration into the project wizard for IDEA 16 release.

0

Please sign in to leave a comment.