Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validateHasCargo keep failing on macOS #24

Open
setoelkahfi opened this issue Oct 12, 2024 · 12 comments
Open

validateHasCargo keep failing on macOS #24

setoelkahfi opened this issue Oct 12, 2024 · 12 comments

Comments

@setoelkahfi
Copy link

Probably related: #9

I keep getting Failed to run 'cargo --version'. You probably don't have 'cargo' executable in PATH error on MacOS while the printed patch definetely has .cargo/bin in it. Any clue?

My gradle file:


val libraries = arrayOf("crate_networking.so")
val cargoArguments = arrayOf("-p", "crate_networking")

cargoNdk {
    module = "../../lib/crate_networking"  // Directory containing Cargo.toml
    librariesNames = arrayListOf(*libraries)
    extraCargoBuildArguments = arrayListOf(*cargoArguments)
    verbose = true
}

@Archdoog
Copy link

I'm also having this issue after upgrading to the latest Android Studio Ladybug | 2024.2.1 Patch 1 on our project https://github.com/stadiamaps/ferrostar.

Even modified the PATH to the exact $HOME/.cargo/bin and same result. Cargo's definitely in the $PATH and the only thing that changed was upgrading Android Studio.

@setoelkahfi
Copy link
Author

Do you still maintain this? @willir

@Archdoog
Copy link

Archdoog commented Nov 4, 2024

Did some exploring, but still haven't figured out a solution.

Notes from debugging

I built out this to very simply test the issue in the project I'm working on.

tasks.register("checkCargo", Exec) {
    workingDir '../common'
    commandLine 'sh', '-c', "cargo --version"
}

This task fails with "No such file or directory", similarly not finding sh nor cargo. Removing the workingDir '../common' fixes the problem and sh & cargo can be found. With workingDir, I get "No such file or directory".

This only happens from Android Studio's gradle run. ./gradlew doesn't experience this issue and I can even run ./gradlew buildCargoNdkRelease successfully. Unfortunately, since the cargoNdk task is tied to build, I still can't actually build the project as a whole.

Some potentially related issues

Will keep working and report back here once I figure out what's messed up.

@ianthetechie
Copy link

ianthetechie commented Nov 4, 2024

That's incredibly strange. It feels like it basically has to be an Android Studio configuration issue, since it works with gradlew on the terminal.

I heard one other report of a user encountering this by the way. Unfortunately I couldn't get any useful debugging information out of them beyond that eventually they got it working. I do know that the user was using some older version of Android Studio initially, and that they ultimately succeeded building with Koala. However, I don't remember if they solved the cargo path issue before or after the Android Studio upgrade. They reported that they had installed Rust via rustup.

I have been able to use the same Android Studio build as @Archdoog without issue. And yesterday I upgraded to Ladybug Patch 2 without incident (builds still working within Android Studio).

Android Studio Ladybug | 2024.2.1 Patch 2
Build #AI-242.23339.11.2421.12550806, built on October 25, 2024
Runtime version: 21.0.3+-79915917-b509.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 10
Metal Rendering is ON
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  i18n.locale=

As far as I can tell, my local builds are using the Temurin JDK 17, and I'm using that for Gradle as well.

image

I've installed Rust via rustup.

@setoelkahfi
Copy link
Author

That's incredibly strange. It feels like it basically has to be an Android Studio configuration issue, since it works with gradlew on the terminal.

I heard one other report of a user encountering this by the way. Unfortunately I couldn't get any useful debugging information out of them beyond that eventually they got it working. I do know that the user was using some older version of Android Studio initially, and that they ultimately succeeded building with Koala. However, I don't remember if they solved the cargo path issue before or after the Android Studio upgrade. They reported that they had installed Rust via rustup.

I have been able to use the same Android Studio build as @Archdoog without issue. And yesterday I upgraded to Ladybug Patch 2 without incident (builds still working within Android Studio).

Android Studio Ladybug | 2024.2.1 Patch 2
Build #AI-242.23339.11.2421.12550806, built on October 25, 2024
Runtime version: 21.0.3+-79915917-b509.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 10
Metal Rendering is ON
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  i18n.locale=

As far as I can tell, my local builds are using the Temurin JDK 17, and I'm using that for Gradle as well.

image I've installed Rust via rustup.

This is interesting. I do have a warning from the Android studio that I have a mismatched JDK setting. I'll retake a look at this.

@w4ll3
Copy link

w4ll3 commented Nov 4, 2024

@setoelkahfi I'm not sure what the root of the issue is, but running Android Studio from a terminal with open -na "Android Studio.app" successfully loads the PATH for me, I guess I'll be satisfied with this for now.

@Archdoog
Copy link

Archdoog commented Nov 5, 2024

@setoelkahfi I'm not sure what the root of the issue is, but running Android Studio from a terminal with open -na "Android Studio.app" successfully loads the PATH for me, I guess I'll be satisfied with this for now.

That works for me too.. Super weird! Some people had success running ./gradlew --stop when encountering a similar issue observed directly when using ./gradlew.

Looking at open -na that's simply just saying open a new instance of the application "Android Studio". I wonder what varies between this and simply clicking the Android Studio app icon.

@willir
Copy link
Owner

willir commented Nov 5, 2024

Hi, I currently don't have the capacity to investigate the issue :-(
But I can accept a PR if you know how to fix it.

@ianthetechie
Copy link

Thanks for the response @willir! We're going to open an issue upstream with Google about this (can post a link here later). So far it's looking like the issue is not specific to this Gradle plugin but is most likely a bug in Android Studio (given that the same error can be reproduced with just a vanilla commandLine invocation: #24 (comment)).

@Archdoog
Copy link

Archdoog commented Nov 5, 2024

https://issuetracker.google.com/issues/377339196

@willir
Copy link
Owner

willir commented Nov 5, 2024

I would also double-check how you set the PATH env variable. The way you call programs from the terminal and not are different, and it is possible to have PATH set from the terminal, but not when you open the program from a normal GUI.

@setoelkahfi
Copy link
Author

Ok, open -na "Android Studio.app" does the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants