49

Trying upload project to bintray and just get error:

Could not determine java version from '9.0.1'.

I read that it's grade bug and it fixed in upper versions, I tried change gradle version to 4.2.1, but get another error:

Gradle sync failed: No such property: FOR_RUNTIME for class: org.gradle.api.attributes.Usage Consult IDE log for more details (Help | Show Log) (571ms)

Gradle properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

Build gradle project

buildscript {
    ext.kotlin_version = '1.1.51'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta7'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.novoda:bintray-release:0.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
no news
  • 1,060
  • 3
  • 14
  • 24

7 Answers7

36

This issue was in gradle version lower than 4.3, so update your gradle.properties to 4.3 or above:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip

Why this error occur?: Because of you have different JDK on your system than your android-studio JDK version.

Therefore your JDK should be compatible with each other, and by following this way you can manage that:

File -> Other settings -> Default project structure

enter image description here

You can use embedded JDK or use your own.


Also you may have some issues with terminal, and that's belong to a conflict between your multiple JDK.

Solution worked with me is to uninstall the java 9 JDK.

  • 3
    I was using Java JDK 9 with Gradle 4.1 when I got this error. Switching to Gradle version 4.3 solved the error. – vovahost Dec 22 '17 at 22:39
  • I solved the problem making the change in gradle/wrapper/gradle-wrapper.properties. I'm using IntellijIDEA/Android Studio. Ref: https://developer.android.com/studio/releases/gradle-plugin.html – Gauss Dec 27 '17 at 17:12
  • i have Gradle 4.4.1 changed distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip and still have the error. – JesseBoyd Jan 19 '18 at 02:11
  • I used `distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip` and the problem had gone. – Eugene Gr. Philippov Apr 18 '19 at 13:01
26

I had this problem on macOS and I solved it by:

Removing the too new java jdk

brew cask uninstall java

And installing an older one

brew tap caskroom/versions
brew cask install java8

All this handled via Homebrew

Gary
  • 7,167
  • 3
  • 38
  • 57
E. Sundin
  • 4,103
  • 21
  • 30
  • I got this one `Error: Cask 'java8' is unavailable: No Cask with this name exists. ` – Paula Kristin Nov 10 '17 at 10:48
  • 5
    @PaulaKristin Perhaps you need to run this first `brew tap caskroom/versions` – E. Sundin Nov 12 '17 at 15:43
  • I found the solution by making my JAVA_HOME on mac to be the same as where my android studio java is located and it solved this issue – Paula Kristin Nov 18 '17 at 12:08
  • This particular error was solved as Paula suggested (pointing to the Android studio JRE). But boy is it painful to upgrade or try and build from the command line! :( – Stephen McCormick Dec 08 '17 at 21:49
  • @StephenMcCormick Honestly, that is a hacky solution. Do you mean that *this particular error* was *only solvable* with the hacky AS JRE method? The phrasing makes it a bit unclear if the answer worked or not. – E. Sundin Dec 10 '17 at 14:17
  • @E.Sundin There may be another solution but I could not find it. By using a different JRE than Android Studio I was receiving that error (and others) and could not find a way to make it work both on the command line and in the IDE without pointing my JAVA_HOME to the same version. If you know a different solution I would be willing to give it a try. – Stephen McCormick Dec 11 '17 at 17:09
  • This is the quickest way to install JDK. – waseefakhtar Mar 09 '18 at 15:44
8

You should also delete Java JDK. Just run the following:

  1. cd /Library/Java/JavaVirtualMachines
  2. sudo rm -rf jdk1

Now check typing 'java' in your terminal.

For more references you can look here: https://www.howtogeek.com/230145/how-to-uninstall-java-on-mac-os-x/

crgarridos
  • 8,758
  • 3
  • 49
  • 61
David
  • 1,365
  • 14
  • 23
  • 1
    Isn't there an alternative way which will use Java from Android Studio Contents directory? – aruke Jan 02 '18 at 13:33
  • @RajanikantDeshmukh `PATH=$PATH:/opt/android-studio/jre/bin` works for me. Add that to your `.bashrc` or `.profile`. Adapt it to wherever you've placed the Android Studio files. – datashaman Jun 12 '18 at 07:46
1

In my case the error was

Could not determine java version from '10'.

I went to preferences in Unity (edit > preferences in windows or Unity > preferences in MAC), external tools, JDK dir and changed went up a couple of levels. I was using JDK 10, but changed to the folder of JDK 8 and this solved the issue.

0

just tried to build with Gradle 4.3, against JDK 9.0.1 - this might possibly function in Android Studio (because the bundled JDK is an elder version), but not when building with Jenkins 2.89.2 (which seems to not support the JDK 9.0.1 yet, literally complaining Could not determine java version from '9.0.1'). bintray might also build with Jenkins, because the error message is somewhat identical.

downgrading to JDK 8 in gradle.properties fixed the issue for me:

org.gradle.java.home=/usr/java/jdk1.8.0_152

combined with gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

Just need to use local gradle distribution Eg : In IntelliJ go to File->settings->Build,Execution,Deployment->Build Tools->Gradle then update the "Use local gradle distribution" as shown in image.

settings window

sytech
  • 29,298
  • 3
  • 45
  • 86
Alok Verma
  • 157
  • 1
  • 5
0

Make sure your files under JDK are accessible. I had same issue because my process was not able to access my JDK files due to proxy issue. Then i changed my JDK path. It worked.

Parthiban
  • 527
  • 2
  • 13
  • 24