skiptools / skip

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

ERROR: JAVA_HOME is set to an invalid directory: /opt/homebrew/opt/java #115

Open MMAFlexfone opened 5 months ago

MMAFlexfone commented 5 months ago

Hi

I have installed Skip, and finished the checkup. The first time the checkup gives me these errors:

[✓] Skip version 0.8.37 (= 0.8.37) [✓] macOS version 14.4.1 (> 13.5.0) [✓] Swift version 5.10 (> 5.9.0) [✓] Xcode version 15.3 (> 15.0.0) [✓] Xcode tools SDKs: 5 [✓] Homebrew version 4.2.20 (> 4.1.0) [✓] Gradle version 8.7 (> 8.6.0) [✗] Java version: error executing java [✓] Android Debug Bridge version 1.0.41 (> 1.0.40) [✓] Android Studio version: 2023.3 [✓] Android tools SDKs: 2 [✓] Resolve dependencies (15.68s) [✓] Build hello-skip (10.83s) [✓] Test Swift (5.46s) [✗] Test Kotlin (1.35s) [✓] Archive iOS ipa (19.92s) [✓] Assemble HelloSkip-release.ipa (0.02s) [✓] Verify HelloSkip-release.ipa 37 KB [✓] Assembling Android apk (343.58s) [✓] Verify HelloSkip-release.apk 12,3 MB [✓] Check Swift Package (0.49s) [✗] Skip 0.8.37 checkup failed with 2 errors

The verbose error said that JAVA_HOME path is wrong, and I need to change it. I did that by doing this:

export JAVA_HOME=/usr/local/opt/openjdk

I ran skip checkup again, and passed the test:

[✓] Skip version 0.8.37 (= 0.8.37) [✓] macOS version 14.4.1 (> 13.5.0) [✓] Swift version 5.10 (> 5.9.0) [✓] Xcode version 15.3 (> 15.0.0) [✓] Xcode tools SDKs: 5 [✓] Homebrew version 4.2.20 (> 4.1.0) [✓] Gradle version 8.7 (> 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: 2 [✓] Resolve dependencies (10.76s) [✓] Build hello-skip (9.4s) [✓] Test Swift (5.42s) [✓] Test Kotlin (103.17s) [✓] Archive iOS ipa (24.09s) [✓] Assemble HelloSkip-release.ipa (0.02s) [✓] Verify HelloSkip-release.ipa 37 KB [⠁] Verify HelloSkip-release.apk[✓] Assembling Android apk (230.49s) [✓] Verify HelloSkip-release.apk 12,3 MB [✓] Check Swift Package (0.38s) [✓] Skip 0.8.37 checkup succeeded in 385.53s

I created the skip project in Terminal and opened it in Xcode, everything looks good, I open a simulator in Android Studio, and build the Xcode project, and now the error show begins. Xcode give me this error:

ERROR: JAVA_HOME is set to an invalid directory: /opt/homebrew/opt/java

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

This is weird, because this just passed in the test. Maybe its Android studio that's the problem, so I try to run the Android project, and this gives me these errors:

SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/maciejmaciejewski/myfone-skip-app/.build/plugins/outputs/myfone-skip-app/MyfoneSkipApp/skipstone/local.properties'.

and:

 Could not determine the dependencies of task ':skipstone:SkipLib:generateDebugRFile'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/xxxx/myfone-skip-app/.build/plugins/outputs/myfone-skip-app/MyfoneSkipApp/skipstone/local.properties'.

Im running Xcode Version 15.3 (15E204a) and Android Android Studio Jellyfish | 2023.3.1

Java version:

openjdk version "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)

Any idea what I'm doing wrong? Thanks.

marcprux commented 5 months ago

Sorry for your troubles. Is this an Intel or ARM (e.g., M1) machine? And if it is ARM, was it upgraded from a previous Intel machine that may have had Homebrew already installed? If so, then the issue may be that Java doesn't run well under Rosetta emulation, and the solution is to re-install Homebrew. More discussion on this issue can be found at Homebrew/discussions/417.

If that isn't the cause of the issue, did you update the export JAVA_HOME= in your ~/.bashrc and/or ~/.zshrc environment file? If you do that, and then re-start Xcode, it should pick up the new environment setting.

In a pinch, you can always just manually override the environment by going to the Xcode target's "Build Phase" and editing the run skip gradle script and just manually adding the line to the beginning of the script:

export JAVA_HOME=/usr/local/opt/openjdk 

e.g., like this:

Screenshot 2024-05-07 at 09 48 13

Please let us know if any of those helps fix the problem!