skiptools / skip

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

Errors when running `skip checkup` if java version > 17 #5

Open Marsgames opened 1 year ago

Marsgames commented 1 year ago

Error after first installation via brew and running skip checkup (with and without --double-check)

Maybe we can provide more info, to help resolving this issue?


Discussed in https://github.com/skiptools/skip/discussions/4

Originally posted by **oluarry** October 27, 2023 This error came up when trying to build in xcode I followed all the steps and made 2 different projects but same error in xcode I ran skip doublecheck here Screenshot 2023-10-26 at 11 18 07 PM
Marsgames commented 1 year ago

Additional info:

Here's build error log when trying to build hello-skip project created via command skip init --open-xcode --appid=com.xyz.HelloSkip hello-skip HelloSkip

note: Building APK for: hello-skip
/Users/rd-headcrab/Library/Developer/Xcode/DerivedData/HelloSkip-dojafehjnlkuenaazualmlxxkzab/Build/Products/../../SourcePackages/artifacts/skip/skip/skip.artifactbundle/macos/skip
Error: Gradle run error: Optional(SkipDriveExternal.ProcessResult.ExitStatus.terminated(code: 1))
GRADLE> 
GRADLE> FAILURE: Build failed with an exception.
GRADLE> 
GRADLE> * What went wrong:
GRADLE> Could not determine the dependencies of task ':HelloSkip:packageDebug'.
GRADLE> > Could not create task ':HelloSkip:compileDebugJavaWithJavac'.
GRADLE>    > Failed to calculate the value of task ':HelloSkip:compileDebugJavaWithJavac' property 'javaCompiler'.
GRADLE>       > No matching toolchains found for requested specification: {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.
GRADLE> 
GRADLE> * Try:
GRADLE> > Learn more about toolchain auto-detection at https://docs.gradle.org/8.4/userguide/toolchains.html#sec:auto_detection.
GRADLE> > Learn more about toolchain repositories at https://docs.gradle.org/8.4/userguide/toolchains.html#sub:download_repositories.
GRADLE> > Run with --stacktrace option to get the stack trace.
GRADLE> > Run with --info or --debug option to get more log output.
GRADLE> > Run with --scan to get full insights.
GRADLE> > Get more help at https://help.gradle.org.
GRADLE> 
GRADLE> BUILD FAILED in 3s
note: Gradle command result: <ProcessResult: exit: terminated(code: 1), output:

>
error: Gradle run error: Optional(SkipDriveExternal.ProcessResult.ExitStatus.terminated(code: 1))
KristofZelei commented 1 year ago

I got the same error, please keep me updated if you find the solution.

KristofZelei commented 1 year ago

I found the solution, I had a newer version of JDK installed. Follow this documentation to uninstall your current version if it is above 17 or simply install version 17.

Marsgames commented 1 year ago

I found the solution, I had a newer version of JDK installed. Follow this documentation to uninstall your current version if it is above 17 or simply install version 17.

Yep, working now. Thanks for your help!

cd /Library/Java/JavaVirtualMachines
sudo rm -rf JDK>17 # replace by your idk version
brew install openjdk@17

Issue can be closed (but info should be added to the installation readme?)

DominatorVbN commented 1 year ago

Even unistalling the newer JDK and installing openjdk@17 did not worked

It only worked when i added below line to the Build Android APK build phase script

export JAVA_HOME="/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home"
export PATH=$JAVA_HOME/bin:$PATH
marcprux commented 1 year ago

We released Skip 0.7.13 last night, which adds openjdk@17 as a dependency of the skip Homebrew package. Run skip upgrade from the command line and then ensure skip checkup passes to get the latest version. If it fails, please post the output of skip checkup --verbose.

Also, if you have a custom JAVA_HOME set (e.g. from your ~/.zshrc file), you may need to unset it for the process you run skip checkup and/or Xcode, otherwise Gradle may try to use an incompatible version.

For some background, Skip would like to be hands-off about which Java version it uses, since Android-focused developers may have limitations and needs for specific version. However, there's an open Gradle issue that prevents JDK 21 from working at all for Android builds; this is a problem for Homebrew's default recommended JDK temurin, which recently got bumped to version 21. So to work around that, we've added openjdk@17 as a prerequisite to Skip's Homebrew formula. In the future, we hope to enable developers to specify which JDK to use at the top-level (e.g., in Sources/App/Skip/skip.yml), but currently it is specified at the very lowest level of SkipUnit.

tejuamirthi commented 1 year ago

skip checkup passes with all checks but Build Android APK phase still fails.

I'm using Skip 0.7.13 but still facing the issue

This solution worked https://github.com/skiptools/skip/issues/5#issuecomment-1783770634

shial4 commented 1 year ago

I had to add

JAVA_HOME=/usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH

instead of /opt/homebrew/opt

marcprux commented 1 year ago

Skip 0.7.16 adds some additional logic to use the /opt/homebrew/opt/openjdk@17 installation rather than the /opt/homebrew/opt/openjdk@21 (which is installed by gradle). This should fix situations where the openjdk@21 install is inadvertently used (and thus triggering the Gradle issue with Java 21).

Please let us know if this problem still affects you and we will re-open the issue.

rzil commented 11 months ago

I am using latest Skip version 0.7.31 but still facing the above issues.

marcprux commented 11 months ago

Can you post the output of skip checkup --verbose?

rzil commented 11 months ago

Can you post the output of skip checkup --verbose?

skipcheckup.txt

marcprux commented 11 months ago

The problem is from this part of the log:

FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseKotlin'.
> Unknown Kotlin JVM target: 21
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 15s
[✗] Assembling Android apk (15.17s)

Can you try forcing using openjdk 17 with the command:

brew link --overwrite openjdk@17

And then check the output of the java -version command:

% java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment Homebrew (build 17.0.9+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.9+0, mixed mode, sharing)
rzil commented 11 months ago

I followed those steps but it didn't work. It seems skip is still choosing JDK version 21? Here is the output.

rubenz@MacBook-Pro ~ % brew link --overwrite openjdk@17
Linking /opt/homebrew/Cellar/openjdk@17/17.0.9... 63 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
rubenz@MacBook-Pro ~ % java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment Homebrew (build 17.0.9+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.9+0, mixed mode, sharing)
rubenz@MacBook-Pro ~ % 
rubenz@MacBook-Pro ~ % skip checkup
[✓] Skip version 0.7.31 (= 0.7.31)
[✓] macOS version 14.1.2 (> 13.5.0)
[✓] Swift version 5.9 (= 5.9.0)
[✓] Xcode version 15.0.1 (> 15.0.0)
[✓] Homebrew version 4.1.22 (> 4.1.0)
[✓] Gradle version 8.5 (> 8.3.0)
[✓] Java version 21.0.1 (> 17.0.0)
[✓] Android Debug Bridge version 1.0.41 (> 1.0.40)
[✓] Android Studio version: 2023.1
[✓] Resolve dependencies (12.61s)
[✓] Build hello-skip (21.59s)
[✓] Test Swift (14.1s)
[✗] Test Kotlin (5.86s)
[✓] Archive iOS ipa (19.01s)
[✓] Assemble HelloSkip-release.ipa (0.01s)
[✓] Verify HelloSkip-release.ipa 23 KB
[✗] Assembling Android apk (14.42s)
[✗] Verify HelloSkip-release.apk: /var/folders/7p/g2ynv5wj1k9dfhcwms4r_z0r0000gn/T//E3FE27FF-E01C-4688-891D-6678D34D8093/hello-skip/.build/Android/app/outputs/apk/release/app-release-unsigned.apk: The file “app-release-unsigned.apk” couldn’t be opened because there is no such file.
[✓] Check Swift Package (0.38s)
[✗] Skip 0.7.31 checkup (96.37s)
Error: 4 errors
Enzo-Dijoux commented 11 months ago

I had the same problem @rzil :

  1. I installed skip using brew command, and by default the openjdk 21 is installed
  2. I installed openjdk 17 and tried 'brew link --overwrite openjdk@17'
  3. 'java -version' display the 17.0.9, but in skip checkup, the 21.0.1 is used

I fixed it, you can follow these instructions (not final fix):

  1. Check your current JAVA_HOME path -> 'echo $JAVA_HOME', in my case it was empty
  2. Update your JAVA_HOME path to the good version (17.0.9) -> 'export JAVA_HOME=$(/usr/libexec/java_home -v17.0.9)'
  3. Run 'skip checkup' again, the version of Java should be 17.0.9

@marcprux Inside the homebrew configuration file , the openjdk@21 is used, maybe the issue could come from here? This is my first time searching for an error with Homebrew, so I might be mistaken.

rzil commented 11 months ago

Yes that did the trick. Need to set JAVA_HOME correctly. For some reason my java_home executable wasn't working but once I resolved that all good.

roslog00 commented 11 months ago

Hello, how do I correctly change the JAVA_HOME path? It shows my path, but the tests are not working.

Снимок экрана 2023-12-08 в 12 08 21 PM
marcprux commented 11 months ago

Apologies for not getting back on this sooner. We're still working through some of the issues with Gradle 8.5 and OpenJDK. If you brew upgrade skip to 0.7.33, that version will try to automatically use opendk@17, and you can manually override if by setting export JAVA_HOME=/opt/homebrew/opt/openjdk@17/ from the terminal before running skip.

Please let us know if this helps.

naticio commented 9 months ago

Apologies for not getting back on this sooner. We're still working through some of the issues with Gradle 8.5 and OpenJDK. If you brew upgrade skip to 0.7.33, that version will try to automatically use opendk@17, and you can manually override if by setting export JAVA_HOME=/opt/homebrew/opt/openjdk@17/ from the terminal before running skip.

Please let us know if this helps.

I followed these steps, still failed in the apk step [✗] Assembling Android apk (13.94s) [✗] Verify HelloSkip-release.apk: /var/folders/9_/xqn4bxx955z6npf3wh5n74nw0000gn/T//A8E02388-080F-455F-ABA4-FF69860E9AFC/hello-skip/.build/Android/app/outputs/apk/release/app-release-unsigned.apk: The file “app-release-unsigned.apk” couldn’t be opened because there is no such file. [✓] Check Swift Package (0.41s) [✗] Skip 0.8.2 checkup (101.02s)

I have 17.0.10 jdk installed. I also have react native/expo installed globally, may this be causing the error?

[✗] Assembling Android apk (12.99s) [✗] Verify HelloSkip-release.apk: /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T//165E34ED-A7BF-4908-BD29-32B3C9334E33/hello-skip/.build/Android/app/outputs/apk/release/app-release-unsigned.apk: The file “app-release-unsigned.apk” couldn’t be opened because there is no such file. executing command: /usr/bin/swift package dump-package --package-path /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/165E34ED-A7BF-4908-BD29-32B3C9334E33/hello-skip warning: 'hello-skip': /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /private/var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/A006AD53-0FE8-4E79-A700-D3B9229942E6/hello-skip/Package.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -vfsoverlay /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/TemporaryDirectory.188kEh/vfs.yaml -swift-version 5 -package-description-version 5.9.0 -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name main -disable-clang-spi -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server' -external-plugin-path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server' -external-plugin-path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -external-plugin-path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/TemporaryDirectory.iri2WW/Package-1.o /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/TemporaryDirectory.iri2WW/Package-1.o -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk --target=arm64-apple-macosx13.0 -forceload /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCompatibilityPacks.a -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -lPackageDescription -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -o /var/folders/9/xqn4bxx955z6npf3wh5n74nw0000gn/T/TemporaryDirectory.KbVot5/hello-skip-manifest Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)

naticio commented 9 months ago

Warning: openjdk@17 17.0.9 is already installed and up-to-date.

nat-serrano@Nats-MacBook-Pro-2 JavaVirtualMachines % java -version
openjdk version "17.0.9" 2023-10-17 OpenJDK Runtime Environment Homebrew (build 17.0.9+0)

nat-serrano@Nats-MacBook-Pro-2 JavaVirtualMachines % echo $JAVA_HOME /opt/homebrew/opt/openjdk@17/

marcprux commented 9 months ago

I think that problem was a different one that should be resolved if you skip upgrade to 0.8.3 (released today). Please try it out and if skip checkup or skip init fails, let us know.

naticio commented 9 months ago

I tried to upgrade to 0.8.4 but didn't actually upgrade nat-serrano@Nats-MacBook-Pro-2 ~ % skip upgrade [✓] Check Skip Updates: 0.8.4 [✓] Upgrade Skip to 0.8.4 (3.55s) nat-serrano@Nats-MacBook-Pro-2 ~ % skip doctor Skip Doctor [✓] Skip version 0.8.2 (= 0.8.2) [✓] macOS version 13.6.1 (> 13.5.0) [✓] Swift version 5.9.2 (> 5.9.0) [✓] Xcode version 15.2 (> 15.0.0) [✓] Xcode tools SDKs: 5 [✓] Homebrew version 4.2.7 (> 4.1.0) [✓] Gradle version 8.6 (> 8.3.0) [✓] Java version 17.0.9 (> 17.0.0) [✓] Android Debug Bridge version 1.0.41 (> 1.0.40) [✓] Android Studio version: 2023.1 [✓] Android SDK licenses: 2 [✓] Check Skip Updates: 0.8.4 [!] A new version is Skip (0.8.4) is available to update with: skip upgrade [!] Skip (0.8.2) checks complete with 1 warning

marcprux commented 9 months ago

Can you try running brew update and then skip upgrade again? It sounds like the Homebrew cache might not be updating automatically.

mmmago commented 6 months ago

Cannot make this work,

Capture d’écran 2024-05-06 à 17 09 25

even by setting JAVA_HOME=$(/usr/libexec/java_home -v17.0.11). Kotlin also fails.

java -version returns :

openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Homebrew (build 17.0.11+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.11+0, mixed mode, sharing)

Any inputs ?

marcprux commented 6 months ago

As you seem to have surmised, this is the problem:

[!] Java version 1.8.0_411 (< 21.0.0) (check JAVA_HOME envrionment: /Library/Internet Plug-Ins/JavaAppletPlugin. plugin/Contents/Home)

You should remove any reference to JAVA_HOME in your ~/.zshrc or ~/.bashrc. Also, we do need JDK 21, not JDK 17. OpenJDK 21 should have been installed when you installed skip with the brew command. So if you remove JAVA_HOME from your environment and run skip checkup from a new shell (making sure that echo $JAVA_HOME does not return anything), then it should pick up the right one.

If that continues to fail, can you post the log file mentioned at the end of the command?

mmmago commented 6 months ago

I tried using JDK 17 because JDK 21 was not working as well. This is what is happening :

Capture d’écran 2024-05-06 à 17 26 45

Here is the log attached :

skip-checkup-2024-05-06T15:23:40Z.txt

marcprux commented 6 months ago

From the log:

GRADLE> GRADLE> ERROR: JAVA_HOME is set to an invalid directory: /opt/homebrew/opt/java GRADLE> GRADLE> Please set the JAVA_HOME variable in your environment to match the GRADLE> location of your Java installation. GRADLE>

Can you check whether the folder /opt/homebrew/opt/java exists? That should be where openjdk was installed by homebrew. You could try re-installing it with brew reinstall openjdk.

Also, was your machine upgraded from an Intel to an ARM (e.g., M1)? If so, the Homebrew installation may be an old Intel-based version, which sometimes installs the wrong architecture for packages. In these cases (which can be identified by the existence of a /usr/local/Homebrew/ directory), we've found that performing a clean Homebrew re-install can help resolve issues.

mmmago commented 5 months ago

From the log:

GRADLE> GRADLE> ERROR: JAVA_HOME is set to an invalid directory: /opt/homebrew/opt/java GRADLE> GRADLE> Please set the JAVA_HOME variable in your environment to match the GRADLE> location of your Java installation. GRADLE>

Can you check whether the folder /opt/homebrew/opt/java exists? That should be where openjdk was installed by homebrew. You could try re-installing it with brew reinstall openjdk.

Also, was your machine upgraded from an Intel to an ARM (e.g., M1)? If so, the Homebrew installation may be an old Intel-based version, which sometimes installs the wrong architecture for packages. In these cases (which can be identified by the existence of a /usr/local/Homebrew/ directory), we've found that performing a clean Homebrew re-install can help resolve issues.

Hello, sorry for the lack of news. Trying this again :

/opt/homebrew/opt/java does not exist. Performing brew reinstall openjdk does not solve the problem.

I do use a M1 Pro machine, /usr/local/Homebrew is indeed existing. Performing a clean install, it now looks like /opt/homebrew/opt/ is existing, but not the java folder, even after re-performing brew reinstall openjdk.

EDIT : I fixed it by running :

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc

then

source ~/.zshrc