skiptools / skip

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

Mac OS: "skip checkup" fails, GRADLE error: "SDK location not found." #172

Open xjki opened 1 month ago

xjki commented 1 month ago

[✓] Skip version 0.10.2 (= 0.10.2) [✓] 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: 5 [✓] Homebrew version 4.3.9 (> 4.1.0) [✓] Gradle version 8.9 (> 8.6.0) [✓] Java version 22.0.1 (> 21.0.0) [✓] Android Debug Bridge version 1.0.41 (> 1.0.40) [✓] Android Studio version: 2024.1 [!] Android SDK licenses need to be accepted with: ~/Library/Android/sdk/tools/bin/sdkmanager --licenses [✓] Resolve dependencies (14.93s) [✓] Build hello-skip (9.95s) [✓] Test Swift (7.86s) [✗] Test Kotlin (10.32s) [✓] Archive iOS ipa (24.86s) [✓] Assemble HelloSkip-release.ipa 37 KB [✓] Verify HelloSkip-release.ipa 37 KB [✗] Assembling Android apk (36.64s) [✗] Verify HelloSkip-release.apk: The file “app-release-unsigned.apk” couldn’t be opened because there is no such file. [✓] Check Swift Package (0.15s) [✓] Check Skip Updates: 0.10.2 [✗] Skip 0.10.2 checkup failed with 3 errors

Error fragment in the log file:

GRADLE> 
GRADLE> FAILURE: Build failed with an exception.
GRADLE> 
GRADLE> * What went wrong:
GRADLE> Could not determine the dependencies of task ':HelloSkip:testDebugUnitTest'.
GRADLE> > 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 '/private/var/folders/mb/cs547vpx4sl168d907w8t5vr0000gn/T/D967E1F7-7385-4CFB-B110-0AAEE80865C2/hello-skip/.build/plugins/outputs/hello-skip/HelloSkipTests/skipstone/local.properties'.

ANDROID_HOME env variable on Mac is set correctly, openJDK java from HomeBrew is used :

~$ env | grep ANDROID
ANDROID_HOME=~/Library/Android/sdk
~$ env | grep JAVA
JAVA_HOME=/usr/local/Cellar/openjdk/22.0.1/libexec/openjdk.jdk/Contents/Home
~$ java --version
openjdk 22.0.1 2024-04-16
OpenJDK Runtime Environment Homebrew (build 22.0.1)
OpenJDK 64-Bit Server VM Homebrew (build 22.0.1, mixed mode, sharing)

Android command-line tools are in the path and available in commandline without path prefix PATH=~/Library/Android/sdk/cmdline-tools/latest/bin: ...

xjki commented 1 month ago

Somehow linked with https://github.com/skiptools/skip/issues/171 pehaps?

xjki commented 1 month ago

Creating new project and setting manual JAVA_HOME override in the project Build Phases-[Run skip graddle] at the top helps (as described here: https://github.com/skiptools/skip/issues/115#issuecomment-2098455645)

marcprux commented 1 month ago

I think the message about the location of the sdkmanager is a red herring – we don't actually expect the tool to be there, that is just the message that we output if we are unable to find any licenses in $ANDROID_HOME/licenses. If you run ls $ANDROID_HOME/licenses, do you see anything in that directory?

We will correct the error message about the expected location of the sdkmanager tool, since you are correct that it is no longer installed there. FTR, it is now installed by Homebrew at /opt/homebrew/bin/sdkmanager.

From your last comment, it sounds like overriding your JAVA_HOME manually is working around this problem. The previous JAVA_HOME that you cite (/usr/local/Cellar/openjdk/22.0.1/libexec/openjdk.jdk/Contents/Home) sounds like it may have been a hold-over from a prior Intel-mac-installed version of Homebrew, which won't work with Skip.

I would recommend removing any old JAVA_HOME entries from your ~/.zshrc and adding:

export JAVA_HOME=/opt/homebrew/opt/java

which will also have the advantage of keep it up with any future JDK updates that come along with Homebrew upgrades.

Please let us know if that helps address the issue. There are a bewildering number of issues that can arise from different combinations of JDKs, so it is nice to get all these on the record so we can improve skip checkup's ability to diagnose and suggest resolutions to these issues.

xjki commented 1 month ago

If you run ls $ANDROID_HOME/licenses, do you see anything in that directory?

Yes, there are license files:

android-googletv-license      android-sdk-license           google-gdk-license            mips-android-sysimage-license
android-sdk-arm-dbt-license   android-sdk-preview-license   intel-android-extra-license

From your last comment, it sounds like overriding your JAVA_HOME manually is working around this problem. The previous JAVA_HOME that you cite (/usr/local/Cellar/openjdk/22.0.1/libexec/openjdk.jdk/Contents/Home) sounds like it may have been a hold-over from a prior Intel-mac-installed version of Homebrew, which won't work with Skip.

I would recommend removing any old JAVA_HOME entries from your ~/.zshrc and adding:

export JAVA_HOME=/opt/homebrew/opt/java

Perhaps tutorial/documentation should list Homebrew reinstall for Apple Silicon Macs (to avoid Intel-mac-installed version of Homebrew being used) as prerequisite if this is the one causing these issues? I suspect many will run into the same issues.

Thanks for answer and keep up the good work!