-t:InstallAndroidDependencies tries to install JDK when no JavaSdkDirectory is specified
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 257
Description
### Android framework version
net8.0-android, net9.0-android
### Affected platform version
macOS, didn't test windows
### Description
The [VSCode docs](https://learn.microsoft.com/dotnet/maui/get-started/installation?tabs=visual-studio-code#android) suggest installing the OpenJDK17 by using the installer from the microsoft download page. This installs fine.
However, to get the Android SDK dependencies, the docs suggest using the `InstallAndroidDependencies` build task.
First of all, it's confusing as it suggests specifying the `-p:JavaSdkDirectory` variable, which having just installed OpenJDK earlier, it's not clear where that even installed to for me to specify it, so perhaps we shouldn't suggest in the docs to set this variable at all.
I think it's supposed to infer the idk path if I do _not_ specify it, and it seems to do that, however it still appears to try and _install_ the idk to that path, which then fails:
```
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.99.0-preview.6.340/tools/Xamarin.Installer.Common.targets(19,3): error : Unable to install the Java SDK into `/Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home`. Please set `$(JavaSdkDirectory)` to a valid non-administrator path.
```
### Steps to Reproduce
1. Install openjdk17
2. Install .NET SDK, and the maui, android workloads.
3. Try to install the dependencies with the build task:
```
mkdir ~/mauiandroidtemp && cd ~/mauiandroidtemp
dotnet new android
dotnet build -t:InstallAndroidDependencies \
-p:AndroidSdkDirectory=/Users/username/Library/Android/sdk \
-p:AcceptAndroidSDKLicenses=True
```
### Did you find any workaround?
I can install to a user location such as `-p:JavaSdkDirectory=/Users/username/Library/Java/openjdk17` but then I've got an extra jdk
### Relevant log output
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.