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

[ARM 32-bit] Unable to start debugging with an android physical device (Hot Reload) #9573

Closed
ArtefactoDev opened this issue Dec 3, 2024 · 35 comments · Fixed by #9869
Closed
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review

Comments

@ArtefactoDev
Copy link

ArtefactoDev commented Dec 3, 2024

Android framework version

net9.0-android

Affected platform version

VS 17.12.2, SDK 9.0.100, Windows 11 24H2

Description

The system compiles the code and sends it to the Android phone, however, after generating the .apk package in the system correctly, Visual Studio does not allow me to debug it.

I can open the generated package on my cell phone without errors, but I cannot debug it using 'hot reload' in any way.

Cell phone model: Motorola G(8)
Android Version: Android 10

Detail, on the same machine I have another application developed in Xamarin for the same cell phone, and I can debug it normally.

Steps to Reproduce

Video Error:
https://github.com/user-attachments/assets/4260e896-6c6a-4fd8-9101-87aff3ee9893

1 - Start Visual Studio
2 - Create a New Project
3 - .NET MAUI App (name: ExemploAndroid)

4 - Net 9
('include sample content' NOT selected)

Change the file 'ExemploAndroid.csproj' to:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
    <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
    <!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->

    <!-- Note for MacCatalyst:
		The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
		When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
		The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
		either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
    <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

    <OutputType>Exe</OutputType>
    <RootNamespace>ExemploAndroid</RootNamespace>
    <UseMaui>true</UseMaui>
    <SingleProject>true</SingleProject>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!-- Display name -->
    <ApplicationTitle>ExemploAndroid</ApplicationTitle>

    <!-- App Identifier -->
    <ApplicationId>com.companyname.exemploandroid</ApplicationId>

    <!-- Versions -->
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <ApplicationVersion>1</ApplicationVersion>

    <!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
    <WindowsPackageType>None</WindowsPackageType>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">28.0</SupportedOSPlatformVersion>
    <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
    <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
    <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
    <!--<AndroidSupportedAbis>true</AndroidSupportedAbis>-->
    <!-- <AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>-->
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0-android|AnyCPU'">
    <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
    <!-- <AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>-->
  </PropertyGroup>


  <ItemGroup>
    <!-- App Icon -->
    <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

    <!-- Splash Screen -->
    <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

    <!-- Images -->
    <MauiImage Include="Resources\Images\*" />
    <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

    <!-- Custom Fonts -->
    <MauiFont Include="Resources\Fonts\*" />

    <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
    <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Maui.Controls" Version="9.0.10" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
  </ItemGroup>

</Project>

Plug in your cell phone (already configured in developer mode), choose to debug and after deployment, Visual Studio stops debugging.

Did you find any workaround?

unfortunately not.

Relevant log output

Build started at 21:20...
1>------ Build started: Project: ExemploAndroid, Configuration: Debug Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>Including assemblies for Hot Reload support
1>ExemploAndroid -> C:\Users\workc\source\repos\ExemploAndroid\bin\Debug\net9.0-android\ExemploAndroid.dll
2>------ Deploy started: Project: ExemploAndroid, Configuration: Debug Any CPU ------
2>Starting deployment to Motorola moto g(8) play ...
2>Deploying to Motorola moto g(8) play ...
Build started.
Project "ExemploAndroid.csproj" (Install target(s)):
There is no application host available for the specified RuntimeIdentifier 'android-arm'.
There is no application host available for the specified RuntimeIdentifier 'android-arm64'.
There is no application host available for the specified RuntimeIdentifier 'android-x86'.
There is no application host available for the specified RuntimeIdentifier 'android-x64'.
Found Java SDK version 17.0.12.
MonoAndroid Tools: c:\program files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.7\tools\
Android Platform API level: 35
TargetFrameworkVersion: v9.0
Android NDK: 
Android SDK: C:\Program Files (x86)\Android\android-sdk\
Android SDK Build Tools: C:\Program Files (x86)\Android\android-sdk\build-tools\35.0.0\
Java SDK: C:\Program Files (x86)\Android\openjdk\jdk-17.0.12\Application Java class: android.app.Application
_OuterIntermediateOutputPath: IntermediateOutputPath: obj\Debuget9.0-android\
Skipping target "ProcessMauiSplashScreens" because all output files are up-to-date with respect to the input files.
Skipping target "ProcessMauiFonts" because all output files are up-to-date with respect to the input files.
Skipping target "ResizetizeImages" because all output files are up-to-date with respect to the input files.
Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files.
Skipping target "_BuildLibraryImportsCache" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateResourceCaseMap" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateResourceDesignerIntermediateClass" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateLayoutBindings" because it has no outputs.
Skipping target "_ConvertResourcesCases" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileResources" because all output files are up-to-date with respect to the input files.
Skipping target "_PrepareUpdateAndroidResgen" because all output files are up-to-date with respect to the input files.
Skipping target "_UpdateAndroidResgen" because all output files are up-to-date with respect to the input files.
Project "ExemploAndroid.csproj" (_ComputeFilesToPublishForRuntimeIdentifiers target(s)):
There is no application host available for the specified RuntimeIdentifier 'android-arm'.
There is no application host available for the specified RuntimeIdentifier 'android-arm64'.
There is no application host available for the specified RuntimeIdentifier 'android-x86'.
There is no application host available for the specified RuntimeIdentifier 'android-x64'.
_OuterIntermediateOutputPath: obj\Debuget9.0-android\IntermediateOutputPath: obj\Debuget9.0-android\android-arm\
Done building project "ExemploAndroid.csproj".
Project "ExemploAndroid.csproj" (_ComputeFilesToPublishForRuntimeIdentifiers target(s)):
There is no application host available for the specified RuntimeIdentifier 'android-arm'.
There is no application host available for the specified RuntimeIdentifier 'android-arm64'.
There is no application host available for the specified RuntimeIdentifier 'android-x86'.
There is no application host available for the specified RuntimeIdentifier 'android-x64'.
_OuterIntermediateOutputPath: obj\Debuget9.0-android\IntermediateOutputPath: obj\Debuget9.0-android\android-arm64\Done building project "ExemploAndroid.csproj".
Project "ExemploAndroid.csproj" (_ComputeFilesToPublishForRuntimeIdentifiers target(s)):
There is no application host available for the specified RuntimeIdentifier 'android-arm'.
There is no application host available for the specified RuntimeIdentifier 'android-arm64'.
There is no application host available for the specified RuntimeIdentifier 'android-x86'.
There is no application host available for the specified RuntimeIdentifier 'android-x64'.
_OuterIntermediateOutputPath: obj\Debuget9.0-android\IntermediateOutputPath: obj\Debuget9.0-android\android-x86\Done building project "ExemploAndroid.csproj".
Project "ExemploAndroid.csproj" (_ComputeFilesToPublishForRuntimeIdentifiers target(s)):
There is no application host available for the specified RuntimeIdentifier 'android-arm'.
There is no application host available for the specified RuntimeIdentifier 'android-arm64'.
There is no application host available for the specified RuntimeIdentifier 'android-x86'.
There is no application host available for the specified RuntimeIdentifier 'android-x64'.
_OuterIntermediateOutputPath: obj\Debuget9.0-android\IntermediateOutputPath: obj\Debuget9.0-android\android-x64\Done building project "ExemploAndroid.csproj".
Skipping target "_LinkAssembliesNoShrink" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateJavaStubs" because all output files are up-to-date with respect to the input files.
Skipping target "_ManifestMerger" because all output files are up-to-date with respect to the input files.
Skipping target "_ConvertCustomView" because all output files are up-to-date with respect to the input files.
Skipping target "_AddStaticResources" because all output files are up-to-date with respect to the input files.
Skipping target "_GeneratePackageManagerJava" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateAndroidAssetsDir" because all output files are up-to-date with respect to the input files.
Skipping target "_PrepareCreateBaseApk" because all output files are up-to-date with respect to the input files.
Skipping target "_CreateBaseApk" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileJava" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileNativeAssemblySources" because all output files are up-to-date with respect to the input files.
Skipping target "_CreateApplicationSharedLibraries" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileToDalvik" because all output files are up-to-date with respect to the input files.
Deleting file "bin\Debuget9.0-android\com.companyname.exemploandroid.apk".
Copying file from "C:\Users\workc\source\repos\ExemploAndroid\obj\Debug
et9.0-android\android\bin\com.companyname.exemploandroid.apk" to "C:\Users\workc\source\repos\ExemploAndroid\bin\Debug
et9.0-android\com.companyname.exemploandroid.apk".
Touching "obj\Debug
et9.0-android\android_debug_keystore.flag".
Deleting file "C:\Users\workc\source\repos\ExemploAndroid\bin\Debug
et9.0-android\com.companyname.exemploandroid-Signed.apk".
C:\Program Files (x86)\Android\android-sdk\build-tools\35.0.0\zipalign.exe -p 16 "obj\Debug
et9.0-android\android\bin\com.companyname.exemploandroid.apk" "bin\Debug
et9.0-android\\com.companyname.exemploandroid-Signed.apk" 
C:\Program Files (x86)\Android\openjdk\jdk-17.0.12\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\35.0.0\lib\apksigner.jar" sign --ks "C:\Users\workc\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 28 --max-sdk-version 35  bin\Debug
et9.0-android\com.companyname.exemploandroid-Signed.apk 
Signed android package 'bin\Debug
et9.0-android\com.companyname.exemploandroid-Signed.apk'
Using cached value from RegisterTaskObject
Found device: 0062963070
Forwarding debugger port 8805
Detecting existing process
> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity"
> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity }
[.exemploandroi] Late-enabling -Xcheck:jni
[.exemploandroi] Unknown bits set in runtime_flags: 0x8000
[DOTNET] AndroidCryptoNative_InitLibraryOnLoad: jint AndroidCryptoNative_InitLibraryOnLoad(JavaVM *, void *) in /__w/1/s/src/native/libs/System.Security.Cryptography.Native.Android/pal_jni.c
[DOTNET] GetOptionalClassGRef: optional class com/android/org/conscrypt/OpenSSLEngineImpl was not found
[monodroid] Failed to create directory '/data/user/0/com.companyname.exemploandroid/files/.__override__/armeabi-v7a'. No such file or directory
[monodroid] Creating public update directory: `/data/user/0/com.companyname.exemploandroid/files/.__override__/armeabi-v7a`
[.exemploandroi] Attempt to remove non-JNI local reference, dumping thread
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8805,server=y,embedding=1,timeout=8
[monodroid-assembly] Unable to open app library directory '/data/user/0/com.companyname.exemploandroid/files/.__override__/armeabi-v7a': No such file or directory
[mono] Listening on 127.0.0.1:8805 (timeout=8 ms)...
[mono] debugger-agent: Timed out waiting to connect.
@ArtefactoDev ArtefactoDev added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Dec 3, 2024
@jonathanpeppers
Copy link
Member

I cannot debug it using 'hot reload' in any way.

This phrasing is confusing, are you trying to debug or use hot reload? The error looks like the debugger is not connecting.

Change the file 'ExemploAndroid.csproj' to:

Does the default template with no changes work? What change did you make that "breaks" things?

The error looks like what you would see if you put the emulator in airplane mode, for example.

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Dec 3, 2024
@ArtefactoDev
Copy link
Author

This phrasing is confusing, are you trying to debug or use hot reload? The error looks like the debugger is not connecting.

I can't debug when I try to use a physical Android device.

Does the default template with no changes work?

No work.
if you try to generate a default template (same Steps to Reproduce ) and try to debug (without any modification) using a physical Android device you will receive the following error:

ADB0020: Mono.AndroidTools.IncompatibleCpuAbiException: The package does not support the CPU architecture of this device

Shouldn't the template, without any modifications, work without errors?

What change did you make that "breaks" things?

Basically, trying to get around the 'ADB0020' error, I only added these lines:

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64;</RuntimeIdentifiers>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'"> <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> </PropertyGroup>

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Dec 3, 2024
@jonathanpeppers
Copy link
Member

if you try to generate a default template (same Steps to Reproduce ) and try to debug (without any modification) using a physical Android device you will receive the following error:

I do this daily, and it is working for me. What device are you using? Can you share a .binlog of the failure? https://aka.ms/binlog

ADB0020: Mono.AndroidTools.IncompatibleCpuAbiException: The package does not support the CPU architecture of this device

ADB0020 is a completely different issue than debugging or hot reload. It means the deploy failed.

Is the device a 32-bit device? If so, you would need to list android-arm as a RuntimeIdentifier as you tried:

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x64;</RuntimeIdentifiers>

A .binlog would allow us to investigate further, thanks!

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Dec 3, 2024
@ArtefactoDev
Copy link
Author

do this daily, and it is working for me. What device are you using?

Not for me, even using the default template without any changes
It works normally if I use the Android emulator, but not with the physical device.

Are you trying an emulator or are you trying to use a physical device for this test? because in the emulator it works normally.
Physical device: Motorola G(8) (Android 10)

Can you share a .binlog of the failure? https://aka.ms/binlog

I attributed the log to open ticket to try to help.EngineTrace_4472.txt
EngineTrace_12004.txt
EngineTrace_23944.txt
EngineTrace_26780.txt
EngineTrace_27524.txt
EngineTrace_28940.txt
EngineTrace_29052.txt
MSBuild_CommTrace_PID_4472.txt
MSBuild_CommTrace_PID_12004.txt
MSBuild_CommTrace_PID_23944.txt
MSBuild_CommTrace_PID_26780.txt
MSBuild_CommTrace_PID_27524.txt
MSBuild_CommTrace_PID_28940.txt
MSBuild_CommTrace_PID_29052.txt
SchedulerState_12004.txt
SchedulerTrace_12004.txt

ADB0020 is a completely different issue than debugging or hot reload. It means the deploy failed.

I know, I explained what happens when you try to debug a physical device using the default template, without any changes.
I just find it strange that the default template without any changes, but with .Net 8 (templante default) works without any problems...

Is the device a 32-bit device? If so, you would need to list android-arm as a RuntimeIdentifier as you tried: (...)

I added all the code from the 'csproj' project to the ticket.
I tried what you said, but it still didn't work.

Maybe the problem is with arm.. But, don't you agree that this should already come by default in the default template, if we consider that more than 90% of the time we will come across ARM devices on Android?

Thank you very much for the excellent help, I'm sure the team will solve it! Because you are excellent!

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Dec 3, 2024
@jonathanpeppers
Copy link
Member

The logs above are not .binlog files. Were you able to collect those?

90% of the time we will come across ARM devices on Android?

The default is android-arm64;android-x64 in .NET 9, you would have a very old Android device for it to be arm and 32-bit.

@ArtefactoDev
Copy link
Author

The logs above are not .binlog files. Were you able to collect those?

binlog.zip

The default is android-arm64;android-x64 in .NET 9, you would have a very old Android device for it to be arm and 32-bit.

It's a possibility.
Is there a way I can get around this to test?

@dellis1972
Copy link
Contributor

You already mentioned the solution for this which is to add android-arm to the list of RuntimeIdentifiers.

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64;</RuntimeIdentifiers>

@ArtefactoDev
Copy link
Author

Device Android:
Motorola g(8) play (SKU: XT2015-2)
Android 10 (api Level 20)
Processor: MediaTek Helio P70M
Kernel Arquitecture: armv7l

Okay, I cleared everything.
I recreated everything from scratch, to test.

1 - I created a default template without any changes to the '.Net Maui App'.

2 - If I try to debug on the Android device), it will give an error:
ADB0020: Mono.AndroidTools.IncompatibleCpuAbiException: The package does not support the CPU architecture of this device. ...

3 - I add the line you passed:
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64;</RuntimeIdentifiers>

4 - Return the error
NETSDK1047: Assets file 'C:\Users\workc\source\repos\MauiApp1\obj\project.assets.json' doesn't have a target for 'net9.0-android/android-arm'. Ensure that restore has run and that you have included 'net9.0-android' in the TargetFrameworks for your project. You may also need to include 'android-arm' in your project's RuntimeIdentifiers.

5 - Add 'project.assets.json' to help

@jonathanpeppers
Copy link
Member

NETSDK1047: Assets file 'C:\Users\workc\source\repos\MauiApp1\obj\project.assets.json' doesn't have a target for 'net9.0-android/android-arm'. Ensure that restore has run and that you have included 'net9.0-android' in the TargetFrameworks for your project. You may also need to include 'android-arm' in your project's RuntimeIdentifiers.

This feels like an IDE/Visual Studio/project system bug, but you may have to close and reopen the project to force it to run NuGet restore again. You might also try dotnet restore at the command-line

@ArtefactoDev
Copy link
Author

ArtefactoDev commented Dec 4, 2024

I try add two lines:

<PropertyGroup>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
<Platforms>AnyCPU;ARM64;ARM32</Platforms>
</PropertyGroup>

The error has stopped choosing arm32, I can generate the apk and add it to the device, but the error that started it all comes back (not able to debug):
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8866,server=y,embedding=1,timeout=8
[mono] Listening on 127.0.0.1:8866 (timeout=8 ms)...
[mono] debugger-agent: Timed out waiting to connect.

I feel like I'm in a loop.

@ArtefactoDev
Copy link
Author

I formatted my machine. I only installed Visual Studio.

I chose the "MAUI App" model and without any modifications I tried to generate the debug on the physical device and I had exactly the same error.

I believe there must be a problem with Visual Studio generation.

@ArtefactoDev
Copy link
Author

Good afternoon everyone, any news?

@jonathanpeppers
Copy link
Member

If you are having trouble with a specific device:

Cell phone model: Motorola G(8)
Android Version: Android 10
armeabi-v7a / 32 bit arm

Does the emulator work just fine or a different device?

We would prioritize this based on how many people are using 32-bit arm devices. Or if it happens to every Motorola device, we would want to investigate.

@ArtefactoDev
Copy link
Author

ArtefactoDev commented Feb 11, 2025

Any arm 32 cell phone.
Basically any cell phone before 2022.

The problem is not the model, but any x32 processor arm.

Samsung, Motorola, Sony, Huawei or any other brand with this processor will not work.

@jonathanpeppers jonathanpeppers removed the need-attention A xamarin-android contributor needs to review label Feb 11, 2025
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Feb 11, 2025
@jonathanpeppers jonathanpeppers changed the title Unable to start debugging with an android physical device (Hot Reload) [ARM 32-bit] Unable to start debugging with an android physical device (Hot Reload) Feb 11, 2025
@WilliamWatterson86
Copy link

@ArtefactoDev did you find any workaround for your device?

@WilliamWatterson86
Copy link

@dellis1972 I tried on an x64 device and get the log
02-26 13:46:52.079 Samsung SM-G973F Warning 27206 monodroid-debug Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8833,server=y,embedding=1,timeout=1740577641

and on x86 yes it shows this every time:
02-26 13:52:12.358 Samsung SM-A137F Warning 29331 monodroid-debug Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8834,server=y,embedding=1,timeout=3

@dellis1972
Copy link
Contributor

@WilliamWatterson86 can you find out what the value for debug.mono.extra is during a failed connection?

adb shell getprop debug.mono.extra

We are trying to figure out where the issue is. I suspect the runtime reading the timeout into a variable which is overflowing. But we need to know what the property is first.

@dellis1972 dellis1972 added the need-info Issues that need more information from the author. label Feb 26, 2025
@WilliamWatterson86
Copy link

@dellis1972 here is the result of that command during a failed session

debug=127.0.0.1:8835,timeout=1740583188,loglevel=0,server=y

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Feb 26, 2025
@dellis1972
Copy link
Contributor

@WilliamWatterson86

have to tried this on other devices or emulators? (32 bit , 64 bit).
Do you get the same results? Or is this a specific arm 32 bit device?

@dellis1972 dellis1972 added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Feb 28, 2025
@dellis1972
Copy link
Contributor

@WilliamWatterson86 do you get the same timeout=3 on those other devices which do not work?

@WilliamWatterson86
Copy link

x64 bit devces seem to be ok, I have tried a couple of these.

I only have one x86 Samsung A13 device. So I havent been able to try it on other x86 devices so far.

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Feb 28, 2025
@dellis1972
Copy link
Contributor

@WilliamWatterson86

do you have android-arm in your RuntimeIdentifiers in your csproj?

@WilliamWatterson86
Copy link

@dellis1972 - yes i have this line:

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>

@akoeplinger
Copy link
Member

akoeplinger commented Feb 28, 2025

I can reproduce this when deploying an arm32 app to an x86 emulator:

Image

the other entry was with x86 RID and has the correct timeout argument.

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 3, 2025
Context dotnet#9573

Not sure why, but we are getting an odd problem were the
`timeout` value we pass to mono for the debugger is not
long enough. This is causing the debugger to timeout.

What we see is `timeout=3` rather than `timeout=1740583188`.
Lets upgrade to use `std:format` to see if that helps as it
with automatically take care of the conversion for us.
dellis1972 added a commit that referenced this issue Mar 5, 2025
Fixes: #9573

Context: 8e1c0e6

A customer reports that they are unable to attach a debugger to
32-bit Android apps:

	> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity"
	> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity }
	…
	[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8805,server=y,embedding=1,timeout=8
	…
	[mono] Listening on 127.0.0.1:8805 (timeout=8 ms)...
	[mono] debugger-agent: Timed out waiting to connect.

Of particular note from the above log messages is the `timeout=8`
value, which is considerably lower than it needs to be, which is a
[value in *milliseconds*][0].  This low value is responsible for the
subsequent `debugger-agent: Timed out` log message.

The `timeout=` value was introduced in commit 8e1c0e6, which used
`%d` to convert the `timeout_time` value; [for context][1]:

	struct RuntimeOptions {
	  int64_t timeout_time = 0;
	  // …
	};
	// …
	char *debug_arg = utils.monodroid_strdup_printf (
	    "--debugger-agent=transport=dt_socket,loglevel=%d,address=%s:%d,%sembedding=1,timeout=%d",
	    loglevel,
	    options.host,
	    options.sdb_port,
	    options.server ? "server=y," : "",
	    options.timeout_time
	);

`options` is a `RuntimeOptions`, and `options.timeout_time` is thus a
`int64_t`, but it's being `printf`d via `%d`.

`%d` is supposed to be an *int*; from [**printf**(3)][2]:

> **d**, **i**
> The *int* argument is converted to signed decimal notation.

which means using `%d` for an `int64_t` will only work properly on
ILP64 targets.  Android, notably, is an ILP32 (32-bit) or
LP64 (64-bit) target, *never* ILP64; it's a wonder this worked
*anywhere*, with any degree of reliability.

The fix is to realize that it doesn't even make sense to be
forwarding `RuntimeOptions::timeout_time` in this manner in the first
place: `RuntimeOptions::timeout_time` is compared against
`time(NULL)`, i.e. it's a [Unix time value][3] (*seconds* since
1970-01-01 UTC), not a value in milliseconds at all!

Replacing the use of `options.timeout_time` with 30000 allows for
a value that is reasonable for the target domain, *and* works
properly and consistently on both ILP32 (32-bit) and LP64 (64-bit)
Android targets.

[0]: https://github.com/dotnet/runtime/blob/9022f3a9b63b56234726606bc5547378b2d08f6b/src/mono/mono/component/debugger-agent.c#L581
[1]: https://github.com/dotnet/android/blob/8e1c0e6e2f4c41c9a24904bb1cea943357d78ac4/src/monodroid/jni/monodroid-glue-internal.hh#L98-L106
[2]: https://linux.die.net/man/3/printf
[3]: https://en.wikipedia.org/wiki/Unix_time
dellis1972 added a commit that referenced this issue Mar 5, 2025
Fixes: #9573

Context: 8e1c0e6

A customer reports that they are unable to attach a debugger to 32-bit Android apps:

	> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity"
	> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity }
	…
	[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8805,server=y,embedding=1,timeout=8
	…
	[mono] Listening on 127.0.0.1:8805 (timeout=8 ms)...
	[mono] debugger-agent: Timed out waiting to connect.

Of particular note from the above log messages is the `timeout=8` value, which is considerably lower than it needs to be, which is a [value in *milliseconds*][0].  This low value is responsible for the subsequent `debugger-agent: Timed out` log message.

The `timeout=` value was introduced in commit 8e1c0e6, which used `%d` to convert the `timeout_time` value; [for context][1]:

	struct RuntimeOptions {
	  int64_t timeout_time = 0;
	  // …
	};
	// …
	char *debug_arg = utils.monodroid_strdup_printf (
	    "--debugger-agent=transport=dt_socket,loglevel=%d,address=%s:%d,%sembedding=1,timeout=%d",
	    loglevel,
	    options.host,
	    options.sdb_port,
	    options.server ? "server=y," : "",
	    options.timeout_time
	);

`options` is a `RuntimeOptions`, and `options.timeout_time` is thus a `int64_t`, but it's being `printf`d via `%d`.

`%d` is supposed to be an *int*; from [**printf**(3)][2]:

> **d**, **i**
> The *int* argument is converted to signed decimal notation.

which means using `%d` for an `int64_t` will only work properly on ILP64 targets.  Android, notably, is an ILP32 (32-bit) or LP64 (64-bit) target, *never* ILP64; it's a wonder this worked *anywhere*, with any degree of reliability.

The fix is to realize that it doesn't even make sense to be forwarding `RuntimeOptions::timeout_time` in this manner in the first place: `RuntimeOptions::timeout_time` is compared against `time(NULL)`, i.e. it's a [Unix time value][3] (*seconds* since 1970-01-01 UTC), not a value in milliseconds at all!

Replacing the use of `options.timeout_time` with 30000 allows for a value that is reasonable for the target domain, *and* works properly and consistently on both ILP32 (32-bit) and LP64 (64-bit) Android targets.

[0]: https://github.com/dotnet/runtime/blob/9022f3a9b63b56234726606bc5547378b2d08f6b/src/mono/mono/component/debugger-agent.c#L581
[1]: https://github.com/dotnet/android/blob/8e1c0e6e2f4c41c9a24904bb1cea943357d78ac4/src/monodroid/jni/monodroid-glue-internal.hh#L98-L106
[2]: https://linux.die.net/man/3/printf
[3]: https://en.wikipedia.org/wiki/Unix_time
@ArtefactoDev
Copy link
Author

ArtefactoDev commented Mar 6, 2025

Wow, beautiful work.
Thank you very much for your hard work!

Please when will this fix be available to use?

@dellis1972
Copy link
Contributor

If we can get Fix Debugger timeout on 32 bit devices for .net 9 #9880 in, then it will be in the next .net 9 Release which is next month I think.

jonpryor pushed a commit that referenced this issue Mar 7, 2025
Fixes: #9573

Context: 8e1c0e6

A customer reports that they are unable to attach a debugger to
32-bit Android apps:

	> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity"
	> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity }
	…
	[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8805,server=y,embedding=1,timeout=8
	…
	[mono] Listening on 127.0.0.1:8805 (timeout=8 ms)...
	[mono] debugger-agent: Timed out waiting to connect.

Of particular note from the above log messages is the `timeout=8`
value, which is considerably lower than it needs to be, which is a
[value in *milliseconds*][0].  This low value is responsible for the
subsequent `debugger-agent: Timed out` log message.

The `timeout=` value was introduced in commit 8e1c0e6, which used
`%d` to convert the `timeout_time` value; [for context][1]:

	struct RuntimeOptions {
	  int64_t timeout_time = 0;
	  // …
	};
	// …
	char *debug_arg = utils.monodroid_strdup_printf (
	    "--debugger-agent=transport=dt_socket,loglevel=%d,address=%s:%d,%sembedding=1,timeout=%d",
	    loglevel,
	    options.host,
	    options.sdb_port,
	    options.server ? "server=y," : "",
	    options.timeout_time
	);

`options` is a `RuntimeOptions`, and `options.timeout_time` is thus a
`int64_t`, but it's being `printf`d via `%d`.

`%d` is supposed to be an *int*; from [**printf**(3)][2]:

> **d**, **i**
> The *int* argument is converted to signed decimal notation.

which means using `%d` for an `int64_t` will only work properly on
ILP64 targets.  Android, notably, is an ILP32 (32-bit) or
LP64 (64-bit) target, *never* ILP64; it's a wonder this worked
*anywhere*, with any degree of reliability.

The fix is to realize that it doesn't even make sense to be
forwarding `RuntimeOptions::timeout_time` in this manner in the first
place: `RuntimeOptions::timeout_time` is compared against
`time(NULL)`, i.e. it's a [Unix time value][3] (*seconds* since
1970-01-01 UTC), not a value in milliseconds at all!

Replacing the use of `options.timeout_time` with 30000 allows for
a value that is reasonable for the target domain, *and* works
properly and consistently on both ILP32 (32-bit) and LP64 (64-bit)
Android targets.

[0]: https://github.com/dotnet/runtime/blob/9022f3a9b63b56234726606bc5547378b2d08f6b/src/mono/mono/component/debugger-agent.c#L581
[1]: https://github.com/dotnet/android/blob/8e1c0e6e2f4c41c9a24904bb1cea943357d78ac4/src/monodroid/jni/monodroid-glue-internal.hh#L98-L106
[2]: https://linux.die.net/man/3/printf
[3]: https://en.wikipedia.org/wiki/Unix_time
jonpryor added a commit that referenced this issue Mar 11, 2025
Fixes: #9573

Context: 8e1c0e6

A customer reports that they are unable to attach a debugger to 32-bit Android apps:

	> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity"
	> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.exemploandroid/crc64358cda76bdc6f75f.MainActivity }
	…
	[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8805,server=y,embedding=1,timeout=8
	…
	[mono] Listening on 127.0.0.1:8805 (timeout=8 ms)...
	[mono] debugger-agent: Timed out waiting to connect.

Of particular note from the above log messages is the `timeout=8` value, which is considerably lower than it needs to be, which is a [value in *milliseconds*][0].  This low value is responsible for the subsequent `debugger-agent: Timed out` log message.

The `timeout=` value was introduced in commit 8e1c0e6, which used `%d` to convert the `timeout_time` value; [for context][1]:

	struct RuntimeOptions {
	  int64_t timeout_time = 0;
	  // …
	};
	// …
	char *debug_arg = utils.monodroid_strdup_printf (
	    "--debugger-agent=transport=dt_socket,loglevel=%d,address=%s:%d,%sembedding=1,timeout=%d",
	    loglevel,
	    options.host,
	    options.sdb_port,
	    options.server ? "server=y," : "",
	    options.timeout_time
	);

`options` is a `RuntimeOptions`, and `options.timeout_time` is thus a `int64_t`, but it's being `printf`d via `%d`.

`%d` is supposed to be an *int*; from [**printf**(3)][2]:

> **d**, **i**
> The *int* argument is converted to signed decimal notation.

which means using `%d` for an `int64_t` will only work properly on ILP64 targets.  Android, notably, is an ILP32 (32-bit) or LP64 (64-bit) target, *never* ILP64; it's a wonder this worked *anywhere*, with any degree of reliability.

The fix is to realize that it doesn't even make sense to be forwarding `RuntimeOptions::timeout_time` in this manner in the first place: `RuntimeOptions::timeout_time` is compared against `time(NULL)`, i.e. it's a [Unix time value][3] (*seconds* since 1970-01-01 UTC), not a value in milliseconds at all!

Replacing the use of `options.timeout_time` with 30000 allows for a value that is reasonable for the target domain, *and* works properly and consistently on both ILP32 (32-bit) and LP64 (64-bit) Android targets.

[0]: https://github.com/dotnet/runtime/blob/9022f3a9b63b56234726606bc5547378b2d08f6b/src/mono/mono/component/debugger-agent.c#L581
[1]: https://github.com/dotnet/android/blob/8e1c0e6e2f4c41c9a24904bb1cea943357d78ac4/src/monodroid/jni/monodroid-glue-internal.hh#L98-L106
[2]: https://linux.die.net/man/3/printf
[3]: https://en.wikipedia.org/wiki/Unix_time

Co-authored-by: Jonathan Pryor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants