skiptools / skip

Skip transpiler for creating SwiftUI apps for iOS and Android
https://skip.tools
GNU Lesser General Public License v3.0
1.09k stars 29 forks source link

Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17... #161

Open jeffc-dev opened 1 week ago

jeffc-dev commented 1 week ago

I'm not entirely sure what happened, but I recently updated to the latest Skip version and started getting the following error when trying to compile my project in Xcode.

* What went wrong:
Could not determine the dependencies of task ':app:packageDebug'.
> Could not create task ':app:compileDebugJavaWithJavac'.
   > Failed to calculate the value of task ':app:compileDebugJavaWithJavac' property 'javaCompiler'.
      > Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any, implementation=vendor-specific} for MAC_OS on aarch64.
         > No locally installed toolchains match and toolchain download repositories have not been configured.

It's not clear to me why it's referencing languageVersion=17. I have the following installed:

jeff@M3-MBP Android % java --version
openjdk 21.0.3 2024-04-16
OpenJDK Runtime Environment Homebrew (build 21.0.3)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.3, mixed mode, sharing)
jeff@M3-MBP Android % echo $JAVA_HOME
/opt/homebrew/Cellar/openjdk@21/21.0.3

Skip checkup seems to work properly:

[✓] Skip version 0.8.55 (= 0.8.55)
[✓] macOS version 14.5 (> 13.5.0)
[✓] Swift version 5.10 (> 5.9.0)
[✓] Xcode version 15.4 (> 15.0.0)
[✓] Xcode tools SDKs: 9
[✓] Homebrew version 4.3.7 (> 4.1.0)
[✓] Gradle version 8.8 (> 8.6.0)
[✓] Java version 21.0.3 (> 21.0.0)
[✓] Android Debug Bridge version 1.0.41 (> 1.0.40)
[✓] Android Studio version: 2023.3
[✓] Android tools SDKs: 4
[✓] Resolve dependencies (6.53s)
[✓] Build hello-skip (7.16s)
[✓] Test Swift (4.58s)
[✓] Test Kotlin (27.85s)
[✓] Archive iOS ipa (12.12s)
[✓] Assemble HelloSkip-release.ipa 37 KB
[✓] Verify HelloSkip-release.ipa 37 KB
[✓] Assembling Android apk (63.56s)
[✓] Verify HelloSkip-release.apk 12.8 MB
[✓] Check Swift Package (0.15s)
[✓] Skip 0.8.55 checkup succeeded in 122.45s

I tried initializing a new Skip app project and compiled it fine with Xcode. I'm not sure what happened to my project, but it seems odd that it would fail to use the proper Java version.

marcprux commented 1 week ago

Sorry for the trouble. We recently downgraded the target bytecode version because Android Studio currently only supports 17. All the Gradle modules (both our own, and your app's) need to harmonize on the JDK version, which appears to sometimes happen automatically and sometimes not (for reasons not yet known to us).

You should be able to fix the issue in your pre-existing project by editing your Android/app/build.gradle.kts file and adding the following inside the android block:

android {
    kotlinOptions {
        jvmTarget = libs.versions.jvm.get().toString()
    }
    … other stuff in android block is unchanged …
}

e.g., it should look like this:

Screenshot 2024-06-27 at 08 36 05

Please let us know if that fixes it.

jeffc-dev commented 1 week ago

I'm afraid that didn't seem to do the trick. I made the addition (in the same spot as your screenshot) and am still getting the following:

* What went wrong:
Could not determine the dependencies of task ':app:packageDebug'.
> Could not create task ':app:compileDebugJavaWithJavac'.
   > Failed to calculate the value of task ':app:compileDebugJavaWithJavac' property 'javaCompiler'.
      > Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any, implementation=vendor-specific} for MAC_OS on aarch64.
         > No locally installed toolchains match and toolchain download repositories have not been configured.
marcprux commented 1 week ago

Can you also try running the Xcode menu: File/Packages/Update to Latest Package Versions and see if that helps?

jeffc-dev commented 6 days ago

I did that and am still getting the same error.

GRADLE> FAILURE: Build failed with an exception.
GRADLE> 
GRADLE> * What went wrong:
GRADLE> Could not determine the dependencies of task ':app:packageDebug'.
error: Could not determine the dependencies of task ':app:packageDebug'.
GRADLE> > Could not create task ':app:compileDebugJavaWithJavac'.
GRADLE>    > Failed to calculate the value of task ':app:compileDebugJavaWithJavac' property 'javaCompiler'.
GRADLE>       > Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any, implementation=vendor-specific} for MAC_OS on aarch64.
GRADLE>          > No locally installed toolchains match and toolchain download repositories have not been configured.

This is what I have for package dependencies (other than my own):

Screenshot 2024-06-28 at 7 21 13 PM

UPDATE:

I also tried deleting DerivedData and ran skip checkup again.

aabewhite commented 4 days ago

Hmm... is this a project you'd be able to just zip and send over to us? Might be faster than going back and forth. If not, I wonder if a fresh "skip init --open-xcode --appid=com.xyz.HelloSkip hello-skip HelloSkip" project compiles and runs from Xcode?

jeffc-dev commented 3 days ago

Interestingly, a new Skip project created from that exact command fails to build with a different error now:

GRADLE> > java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException:
com.android.ddmlib.InstallException: INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade detected:
Update version code 1 is older than current 49

A skip checkup still seems to pass.

jeff@M3-MBP components-tester (debug) % skip checkup
[✓] Skip version 0.9.0 (= 0.9.0)
[✓] macOS version 14.5 (> 13.5.0)
[✓] macOS architecture: ARM
[✓] Swift version 5.10 (> 5.9.0)
[✓] Xcode version 15.4 (> 15.0.0)
[✓] Xcode tools SDKs: 9
[✓] Homebrew version 4.3.8 (> 4.1.0)
[✓] Gradle version 8.8 (> 8.6.0)
[✓] Java version 21.0.3 (> 21.0.0)
[✓] Android Debug Bridge version 1.0.41 (> 1.0.40)
[✓] Android Studio version: 2023.3
[✓] Android tools SDKs: 4
[✓] Resolve dependencies (18.23s)
[✓] Build hello-skip (7.65s)
[✓] Test Swift (4.65s)
[✓] Test Kotlin (30.73s)
[✓] Archive iOS ipa (16.82s)
[✓] Assemble HelloSkip-release.ipa 37 KB
[✓] Verify HelloSkip-release.ipa 37 KB
[✓] Assembling Android apk (78.11s)
[✓] Verify HelloSkip-release.apk 12.7 MB
[✓] Check Swift Package (0.21s)
[✓] Skip 0.9.0 checkup succeeded in 156.93s

I'm not getting this issue with my project, but the same one as described before.

I have created a very minimized version of that project (stripping out all of my own code) that still exhibits this behavior on my machine (Xcode 15.4, macOS 14.5, MBP M3 Max) even with the very latest package versions. I'm sending it your way now via email.

aabewhite commented 3 days ago

The new error you're seeing just means that you need to un-install any old version of that app from the Android emulator. It'll work after that.

aabewhite commented 3 days ago

On the topic of the existing project: first, thanks or sending it. Unfortunately it works for me right out of the box. But I do have a suggestion. Please try commenting out the "jvmToolchain" line in the "kotlin" section of the build.gradle.kts file:

import java.util.Properties

plugins {
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.android.application)
    id("skip-build-plugin")
}

skip {
}

kotlin {
    // jvmToolchain(libs.versions.jvm.get().toInt())
}
...
jeffc-dev commented 2 days ago

I commented out that line and re-compiled -- it worked, both in the minimized project I sent you and my full project.

🎉

Thank you so much for your help.

Is this something you'll need to revisit on your end, or is it okay to leave this commented out?

aabewhite commented 2 days ago

Hurray!

It's safe to keep commented out. You now have our recommended configuration. We haven't put up more docs and tooling around it yet because we're also preparing to move to the Kotlin 2 compiler, which is going to require additional changes. So we're trying to do all the tooling and docs at once.