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

wrong android sdk requirement #1631

Closed
HobDev opened this issue Nov 25, 2024 · 9 comments
Closed

wrong android sdk requirement #1631

HobDev opened this issue Nov 25, 2024 · 9 comments
Assignees
Labels
area-maui bug Something isn't working

Comments

@HobDev
Copy link

HobDev commented Nov 25, 2024

Type: Bug

I recently installed Visual Studio code after installing .NET 9 on a clean PC. When I check Android environment it always show that the Android SDK version 34 is not installed.
But it should check for Android SDK version 35 which is already installed and also the path is set in VS Code.

Extension version: 1.5.34
VS Code version: Code 1.95.3 (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs AMD Ryzen 5 3600XT 6-Core Processor (12 x 3793)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.93GB (5.45GB free)
Process Argv --crash-reporter-id 7efd9556-740e-43d4-91b8-9e199325f5bc
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
g316j359:31013175
dvdeprecation:31068756
dwnewjupytercf:31046870
2f103344:31071589
nativerepl2:31139839
pythonrstrctxt:31112756
cf971741:31144450
iacca1:31171482
notype1cf:31157160
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530

@webreidi webreidi added bug Something isn't working area-maui labels Nov 25, 2024
@jonpryor
Copy link
Member

jonpryor commented Dec 3, 2024

@HobDev: could you please provide the contents of the "Output" panel (Ctrl+Shift+U, then select ".NET MAUI" from the drop-down)?

For example, for reference, I followed the MAUI installation instructions:

  1. Created a new Dev Box instance with just VSCode installed.

  2. Installed .NET 9 from dotnet-sdk-9.0.100-win-x64.exe

  3. Installed OpenJDK 17.0.13 from: https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-17

  4. Installed the MAUI workload:

    dotnet workload install maui
    
  5. Installed the Android SDK:

    mkdir -p ${env:LOCALAPPDATA}\Android\Sdk
    dotnet new android -n provision-helper
    cd provision-helper
    dotnet build -t:InstallAndroidDependencies -f:net9.0-android -p:AndroidSdkDirectory=${env:LOCALAPPDATA}\Android\Sdk -p:AcceptAndroidSDKLicenses=True
  6. Within VSCode, installed the .NET MAUI extension

  7. Opened the provision-helper project created in (5), then Ctrl+Shift+P > .NET MAUI: Configure Android > Refresh Android environment

  8. The results are written to the "Output" panel (Ctrl+Shift+U, then select ".NET MAUI" from the drop-down):

Image

with contents:

ANDROID ENVIRONMENT STATUS: 12/2/2024, 7:12:02 PM
 
Here is the status of your Android development environment:
 
Required components:
 
	✓ Java SDK - INSTALLED (version '17.0.13')
		- Path: 'C:\Program Files\Microsoft\jdk-17.0.13.11-hotspot' (Workload)

	✓ Android SDK - INSTALLED
		- Path: 'C:\…\AppData\Local\Android\sdk' (VSCode settings)
 
		✓ platforms/android-35 - INSTALLED (version '1')
		✓ build-tools/35.0.0 - INSTALLED (version '35.0.0')
		✓ platform-tools - INSTALLED (version '34.0.5')
		✓ cmdline-tools/12.0 - INSTALLED (version '12.0')
 
Optional components:
 
	✗ Android Virtual Device (AVD) - INCOMPLETE (Required for emulator usage)
		- AVD Path: ''
		- AVD devices - NOT DETECTED
 
		✗ emulator - NOT INSTALLED
		✗ system-images/android-35/google_apis/x86_64 - NOT INSTALLED (Required for default platform)
 
IMPORTANT:
- If you are sharing the Android SDK location with Android Studio, the recommended way to install/update the SDK and accept licenses is by using Android Studio.
- If you are sharing the Java SDK location with Visual Studio, the recommended way to install/repair the SDK is by using the Visual Studio installer.
 
SUGGESTION:
- Android SDK - There are optional Android SDK components required for emulator usage that we recommend to installed/upgraded: "emulator" "system-images/android-35/google_apis/x86_64".
	1. Install the Android SDK components:
		- From the command palette, choose '.NET MAUI: Configure Android', select 'How to configure Android', and follow the instructions.
		- Alternatively, you can try installing the components by opening a Terminal, navigating to directory 'C:\Users\jopryo\AppData\Local\Android\sdk\cmdline-tools\12.0\bin' and then running: 'sdkmanager "emulator" "system-images;android-35;google_apis;x86_64"'. Then, from the command palette, choose '.NET MAUI: Configure Android', and 'Refresh Android environment'.

I do not see any messages stating that "Android SDK version 34 is not installed".

@jonpryor
Copy link
Member

jonpryor commented Dec 3, 2024

Howver, with respect to my previous comment, if I update the .csproj file to instead have:

<TargetFramework>net8.0-android</TargetFramework>

that is, target .NET 8 instead of .NET 9, then .NET MAUI reports errors:

ACTION REQUIRED:
✗- Android SDK - Ensure that the required Android SDK components are installed: "platforms/android-34" "build-tools/34.0.0".
	1. Install the Android SDK components:
		- From the command palette, choose '.NET MAUI: Configure Android', select 'How to configure Android', and follow the instructions.
		- Alternatively, you can try installing the components by opening a Terminal, navigating to directory 'C:\…\AppData\Local\Android\sdk\cmdline-tools\12.0\bin' and then running: 'sdkmanager "platforms;android-34" "build-tools;34.0.0"'. Then, from the command palette, choose '.NET MAUI: Configure Android', and 'Refresh Android environment'.
Take into account that the .NET MAUI Android SDK recommends specific component versions and if you decide to not use them the building and debugging may not work well.
 
SUGGESTION:
- Android SDK - There are optional Android SDK components required for emulator usage that we recommend to installed/upgraded: "emulator" "system-images/android-34/google_apis/x86_64".
	1. Install the Android SDK components:
		- From the command palette, choose '.NET MAUI: Configure Android', select 'How to configure Android', and follow the instructions.
		- Alternatively, you can try installing the components by opening a Terminal, navigating to directory 'C:\…\AppData\Local\Android\sdk\cmdline-tools\12.0\bin' and then running: 'sdkmanager "emulator" "system-images;android-34;google_apis;x86_64"'. Then, from the command palette, choose '.NET MAUI: Configure Android', and 'Refresh Android environment'.

We thus need to re-run the InstallAndroidDependencies target:

dotnet build -t:InstallAndroidDependencies -f:net8.0-android -p:AndroidSdkDirectory=${env:LOCALAPPDATA}\Android\Sdk -p:AcceptAndroidSDKLicenses=True

Note -f:net8.0-android instead of the original -f:net9.0-android. Alternatively, if this is just a .NET for Android project, and <TargetFramework/> (singular) is used and <TargetFrameworks/> (plural) is not used, then the -f … value may be omitted entirely.

Now when Ctrl+Shift+P > .NET MAUI: Configure Android > Refresh Android environment, I get:

ANDROID ENVIRONMENT STATUS: 12/2/2024, 8:05:59 PM
 
Here is the status of your Android development environment:
 
Required components:
 
	✓ Java SDK - INSTALLED (version '17.0.13')
		- Path: 'C:\Program Files\Microsoft\jdk-17.0.13.11-hotspot' (Workload)

	✓ Android SDK - INSTALLED
		- Path: 'C:\…\AppData\Local\Android\sdk' (VSCode settings)
 
		✓ platforms/android-34 - INSTALLED (version '3')
		✓ build-tools/34.0.0 - INSTALLED (version '34.0.0')
		✓ platform-tools - INSTALLED (version '34.0.5')
		✓ cmdline-tools/11.0 - INSTALLED (version '11.0')

Notice that platforms/android-34 is now INSTALLED.

@jonpryor
Copy link
Member

jonpryor commented Dec 3, 2024

The shorter version is that the InstallAndroidDependencies target only installs the dependencies required to build the project upon which the target is run. Dependencies will vary based on $(TargetFramework) version: .NET 8 requires android-34, .NET 9 requires android-35, .NET 10 will probably require android-37, etc. Open or create a new project, and a possibly different set of dependencies will be required.

@mauroa mauroa added the needs-more-info Needing more information, waiting on OP label Dec 3, 2024
@HobDev
Copy link
Author

HobDev commented Dec 6, 2024

@jonpryor Thanks for detailed explanation. You are correct the issue is only with the project which I upgraded from .NET 8 to .NET 9. Other projects correctly recongnize the latest version of Android SDK. Do I have to move the code of the effected project to the project which is created with new template. Can't I fix this issue in the same project. I already replaced the net-8.0 references with net-9.0 in csproj and updated all the NuGets.

@github-actions github-actions bot removed the needs-more-info Needing more information, waiting on OP label Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

@mauroa, the 'needs-more-info' label has been removed upon receiving further response from the original bug filer.

@emaf emaf assigned jonpryor and unassigned tondat Dec 9, 2024
@jonpryor
Copy link
Member

jonpryor commented Dec 9, 2024

@HobDev wrote:

Do I have to move the code of the effected project to the project which is created with new template. Can't I fix this issue in the same project. I already replaced the net-8.0 references with net-9.0 in csproj and updated all the NuGets.

I don't understand the question or scenario.

In particular:

Can't I fix this issue in the same project.

Why can't you fix it in the same project?

I think your scenario is:

  1. You have a project which was initially created under .NET 8:
    • MAUI
      <TargetFrameworks>net8.0-android;<!-- other targets… --></TargetFrameworks>
    • or .NET for Android:
      <TargetFramework>net8.0-android</TargetFramework>
  2. You then update it to target .NET 9:
    • MAUI
      <TargetFrameworks>net9.0-android;<!-- other targets… --></TargetFrameworks>
    • or .NET for Android:
      <TargetFramework>net9.0-android</TargetFramework>
    • Plus update other NuGet/etc. references to use .NET 9 versions
  3. The project fails to build.

Is that your scenario? If so, what build errors do you see?

Or is that not your scenario?

@HobDev
Copy link
Author

HobDev commented Dec 20, 2024

@jonpryor

I have a project which was initially created under .NET 8:
MAUI
<TargetFrameworks>net8.0-android;<!-- other targets… --></TargetFrameworks>

I then update it to target .NET 9:
MAUI
<TargetFrameworks>net9.0-android;<!-- other targets… --></TargetFrameworks>

Plus update other NuGet/etc. references to use .NET 9 versions.

The project fails to build.

This is exactly my scenario.

If I manually set the Android location from the command Select Android SDK location to the same location as it is already set it recognize the installed Android SDK version 35 and ask for correct requirement (version 35). But when I try to debug I get the following error.
C:\Users\spara\.nuget\packages\dependencies.gradle\8.6.0.1\buildTransitive\Dependencies.Gradle.targets(30,3): error : Could not find 7zip.exe in Xamarin installation

Get few warnings like
C:\Users\spara\repos\Dome-backend\Player\Player.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Navigation.Common.Ktx 2.7.6 requires Xamarin.AndroidX.Navigation.Common (>= 2.7.6 && < 2.7.7) but version Xamarin.AndroidX.Navigation.Common 2.8.0.1 was resolved.

After a restart the VSCode again expect the wrong android sdk requirement as described in the issue. But still if I debug I get the same error as above. Below is the terminal output:

The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command dotnet build -t:Run -p:Configuration=Debug -f net9.0-android -p:AdbTarget=-s%20MyAndroidVirtualDevice-API35 -p:AndroidAttachDebugger=true -p:AndroidSdbTargetPort=63786 -p:AndroidSdbHostPort=63786 -p:CustomAfterMicrosoftCSharpTargets="c:\Users\spara\.vscode\extensions\ms-dotnettools.dotnet-maui-1.5.34-win32-x64\dist\resources\Custom.After.Microsoft.CSharp.targets" -p:MauiVSCodeBuildOutputFile="C:\Users\spara\AppData\Local\Temp\dotnet-maui\maui-vsc-6d445146-24ed-46b9-9ce8-4626a384658f.json" -p:AndroidSdkDirectory="c:\Users\spara\AppData\Local\Android\Sdk" C:\Users\spara\repos\Dome-backend\Player\Player.csproj" terminated with exit code: 1.

@HobDev
Copy link
Author

HobDev commented Dec 25, 2024

I installed 7Zip on my windows 11 machine. Now I am getting new error:

 C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.145\tools\Xamarin.Android.Common.targets(893,3): error XACDJ7028:
      System.IO.FileNotFoundException: Could not find file 'C:\Users\spara\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-serialization-json-jvm\1.6.2\8f4df208edf91a3012e7a27ccd02
      f386d4bfc8c6\kotlinx-serialization-json-jvm-1.6.2.jar'.
      File name: 'C:\Users\spara\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-serialization-json-jvm\1.6.2\8f4df208edf91a3012e7a27ccd02f386d4bfc8c6\kotlinx-serialization-json-jv
      m-1.6.2.jar'
         at System.IO.FileInfo.get_Length()
         at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj)
         at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location)
         at System.Collections.Generic.HashSet`1.Add(T item)
         at System.Linq.Enumerable.DistinctIterator`1.MoveNext()
         at System.Linq.Enumerable.IteratorSelectIterator`2.ToArrayNoPresizing()
         at System.Linq.Enumerable.IteratorSelectIterator`2.ToArray()
         at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent(IEnumerable`1 filePaths)
         at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.RunTask()
         at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

Get this error with .net 8 and .net 9 both.

@HobDev
Copy link
Author

HobDev commented Jan 2, 2025

The actual issue of wrong android sdk requirement is resolved. I don't able to build because of the NuGet Stripe.MAUI which is not compatible with .NET 9.

@HobDev HobDev closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-maui bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants