maui: .NET 8 Preview 6 MAUI project fails to build for Android in the command line as it's unable to detect the Android SDK path
Description
.NET 8 Preview 6 MAUI project fails to build for Android in the command line as it’s unable to detect the Android SDK path.
Android SDK is installed in the %LocalAppData%\Android\Sdk folder on my machine.
And .NET CLI is repeatedly looking for the SDK from the Program Files folder.
After installing the latest preview version of VS2022 (17.7 Preview 3.0), found that the Android SDK path is reset to Program Files, have manually modified the setting to rightly point it to the Local AppData folder.
VS Setting: Xamarin -> Android Settings -> Android SDK Location
Post update of this setting, it is working inside VS IDE.
But it fails to build on the CLI.
Have tried setting the ANDROID_HOME and ANDROID_SDK_ROOT environment variables and even added the path to the PATH environment variable. But ended in vain as it always looks for the Android SDK from the Program Files folder (refer to the log section).
Note: Have selected the Version with bug field as Unknown/Other as the .NET 8 Preview 6 is not yet added.
Steps to Reproduce
- Create a new .NET MAUI project (dotnet new maui)
- Build the project targeting the Android platform (dotnet build -f net8.0-android)
Link to public reproduction project repository
Default template itself is suffice, no authored code
Version with bug
8.0.0-preview.6.8686
Last version that worked well
8.0.0-preview.5.8529
Affected platforms
Android
Affected platform versions
Android 34.0
Did you find any workaround?
Validate and Update, if necessary, the value of Android SDK location within VS IDE. That’s the only option for now.
Refer to the comments for a workaround.
Relevant log output
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.6.359\tools\Xamarin.Android.Tooling.targets(100,5): error
XA5207: Could not find android.jar for API level 34. This means the Android SDK platform for API level 34 is not installed. Either
install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an
API version that is installed. (C:\Program Files (x86)\Android\android-sdk\platforms\android-34\android.jar missing.) [E:\MAUI\NET_8\Preview_6\MauiApp2\MauiApp2.csproj::TargetFramework=net8.0-android]
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 18 (11 by maintainers)
Seems like I found the core problem, .NET CLI is proactively making use of a single quote (
') assuming that there would be a space in the path of the Android SDK directory (maybe due to the influence of the Program Files folder). But when a single quote is used within the CLI, it is complaining. This could be due to the way MSBuild parameters are being parsed.The below command with the value within the single quotes is failing with the same error as like without the
AndroidSdkDirectoryproperty mentioned.Whereas the value within the double quotes works perfectly fine.
@egvijayanand Thank you issue solved. Have a great day
Check earlier comment👆
AndroidSdkDirectory should point only to the root directory.
dotnet build -f net8.0-android -p:AndroidSdkDirectory=E:\Android\android-sdk
cc @jonathanpeppers @jonpryor