0

I have several JDKs installed on my Windows 10, including versions 8, 11 and 17. My system default is 17, since I want to use latest features in new programs.

I am trying nativescript, and trying to run a program fails with "Unknown bytecode version 61". As per NativeScript Android Build fails with an exception - Unsupported class file major version 57, I understand that this is a JDK version problem, and that nativescript requires JDK 8. However I don't know how to tell ns/gradle to use my JDK 8. Changing JAVA_HOME did not help.

I tried adding org.gradle.java.home=C:\\Program Files\\Amazon Corretto\\jdk1.8.0_302 to gradle.properties, however this file is generated and in some cases my changes get deleted.

I can change my PATH to prefer Java 8 before 17, however I don't want to change my entire dev machine defaults to an old JDK just for nativescript.

f.khantsis
  • 3,256
  • 5
  • 50
  • 67

1 Answers1

0

I think you can use the -D for one time usage , the official doc got this covered for you .

for example you ll be using it like this

gradle build -Dorg.gradle.java.home=/path/to/prefered/jdk

EDIT:

I find a way to that with your build.gradle by defining a gradle task to set this property

task addProperty() {
     project.ext."org.gradle.java.home" = "/path/to/desired/jdk-version"
   }
   tasks.named("build") { mustRunAfter(addProperty) }

after running gradle build , you can check that this property has been added .

Hope this helps .

George
  • 2,292
  • 2
  • 10
  • 21
  • and how do I do this, considering that ns client is what's calling gradle build for me? – f.khantsis Nov 14 '21 at 07:51
  • Have you checked [here](https://v7.docs.nativescript.org/core-concepts/android-runtime/advanced-topics/gradle-hooks?fbclid=IwAR21rafcYV22yIP3atUpIfa5d-HU4ywrHXpbLOmmRTDoYCFzaTHCOd1mRcM#gradleproperties) , it tells that you can easily set the `org.gradle.java.home=/path/to/prefered/jdk` to the gradle.properties . – George Nov 14 '21 at 10:04
  • i have updated the answer , hope this help . – George Nov 14 '21 at 12:08
  • I created a buildscript.gradle file with the above task code and it came back with `Could not find method task() for arguments [addProperty, buildscript_6xcal0jvettdnt0okkjlw6rn9$_run_closure1@3665b5b2] on object of type org.gradle.api.internal.initialization.DefaultScriptHandler.` – dashman Apr 14 '22 at 20:27