Open MSicc opened 1 year ago
Thanks for the feedback
Try updating VS4mac, please.
This might be relevant (similar adb
issue)
Hi @MSicc. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Thanks for the feedback
Try updating VS4mac, please.
This might be relevant (similar
adb
issue)
This happens with the latest VS4Mac, fresh install after uninstalling all .NET things via the provided scripts (including reboot).
Unless a new version came out since the initial post, I can't update...
@MSicc
I assume you are using USB debugging? If so, can you try to setup Wifi Debugging on that device and see if that helps? We are aware of a "hang" issue during fast deployment, but we are not sure what is causing it at this time. This issue should probably be moved to the xamarin/xamarin-android repo as its not related to VSForMac or Maui really.
@dellis1972
I am using USB debugging, yes.
In the meantime, I was able to debug a Xamarin.Forms and a MAUI app via a Windows VM running in Parallels on the same Mac via cable on the same device.
I wonder what debugging via Wi-Fi should change?
@MSicc
We have a theory around the adb shell
input buffer. The Fast dev system sends data over stdin
to the device. We suspect that certain sizes of data overload this buffer and cause a hang.
I have a device running android 13 which I think we can replicate a similar issue with so I'm going to be investigating this to see if we can find the cause.
We checked the diff between Xamarin.Classic (which Xamarin.Forms uses) and .net 7 (whcih Maui uses) and there isn't anything obvious which would cause a hang. So it must be something to do with the interaction with adb
itself.
In the mean time do try the Wi-Fi debugging if you get a chance. I found it to be quite stable on the whole.
@dellis1972 I will try when I get the chance.
I had the same problem and eventually got it to work by adding this to the project file...
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
Adding in, this has just started happening to me. I don't use MAUI a lot so not sure when I it broke, but a project that was last touched maybe now 3 months ago will no longer deploy.
Changing to wireless debugging did allow it to deploy with no issue.
Swapped back to USB debugging to confirm that I can deploy Xamarin.Forms projects fine. Possibly data you have on your side, but also just confirming that when deploying MAUI project I don't get to the InstallPackage
line.
Target _Upload:
Using cached value from RegisterTaskObject
Found device: XXXYYYZZZ
InstallPackage
Relative (different) project sizes: MAUI - 9.7MB Xamarin.Forms - 37.3MB
Happy to test any fixes if needed @dellis1972 .
We are seeing a few issues with hanging deployments on certain android devices. We are currently not sure what causes this problem. It seems to be related to the OS that is installed on the device.
Switching to Wireless Debugging or enabling EmbedAssembliesIntoApk
are the only work around at this time. Wireless Debugging would probably provide a better experience.
I am working on some better error handling. The idea is to detect when this occurs and use a fallback (but slower method) of fast deployment. But issue a warning that Wireless Debugging might be better for this device.
Update:
Swapped back to USB debugging to confirm that I can deploy Xamarin.Forms projects fine.
I just did a fresh macOS install, this issue now appears to be happening for my Xamarin.Forms app now. I tried the EmbedAssembliesIntoApk
solution but that did not work, however swapping to wireless debugging did fix it.
Is this an issue that belongs in the xamarin-android
repo, or is it still a MAUI specific issue and I have something else going on here with XF which is causing a similar problem?
For some reason having wireless debugging enabled on my phone won't allow it to show up with adb devices
, unsure what else I am meant to do there. However running adb tcpip...
and adb connect...
command allow the device to show up (as well as a duplicate usb device -_-). Unsure if this little script helps anyone else, but adding this helper function (for macOS using zsh) allows me to connect to android over wireless debugging each morning I come to work. In .zprofile
I added the following lines,
android_wireless () {
adb tcpip 5555
adb connect 192.168.1.XYZ
}
where 192.168.1.XYZ
is the static IP address of my Android device. Now when I start work in the morning I can just run android_wireless
from my terminal and my device will be setup to debug.
Are there any instructions for dealing with this particular issue?
I am running the app development on VS4Mac and I can't connect to a real device nor to an Android simulator. Do I have to set up the dev environment on a Windows machine to keep the development running?
@MouratidisA see this https://github.com/dotnet/android/issues/9261. Wireless Debugging seems to be more stable at this moment.
Still an issue. Brand new Android 13 device, wired connection for debug. Spend more time with maui issues than writing code.
We have a backup path being released in .net 8 RC 2.1 that should hopefully improve things a bit.
I have this issue on my Pixel 6 API 32. Any thoughts on when to expect the release/fix? Wifi debugging does work.
It should be in .net 8 RC 2.1.
Note its not a "fix", something in a recent Android OS update is causing our Fast Deployment system to hang. So we added code to detect this and fallback to a slower method so that the deployment can continue,
Verified this issue on 17.6.8 (build 400) with .NET SDK 7.0.312/8.0.101, it still repro on device Google Pixel 6a (API32), but not repro on Xiaomi (API30) and SamSung (API33)
I have this issue with a Pixel 7a API 34 and Pixel 5a API 33 with usb connection to an older Intel Mac (Sonoma).
Deployment works correctly with usb connection to an M1 Mac (Sonoma).
Same config on both Macs: Rider 2023.3.3, workload maui-android 8.0.3/8.0.100 SDK 8.0.100
.
@joemather
If you are still seeing an issue, getting some diagnostic logs would really help us see what is going on.
Can you run the following on your project
dotnet build <your project> -t:Install -p:_FastDeploymentDiagnosticLogging=true -bl
make sure you get the error you are seeing in the output before uploading the logs. If the install hangs you might need to use
dotnet build <your project> -t:Install -p:_FastDeploymentDiagnosticLogging=true -v:diag > build.log
since the -bl
option creates an archive, and if the build hangs then the archive is not correctly generated on cancellation of the task.
Hi @MSicc. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@dellis1972
OK, I will collect the logs.
In the meantime, here is some more info...
Just like @MSicc reported, usb deployment usually hangs on Found device
. But when it does crash, the output looks like this:
...
Skipping target "_CopyPackage" because all output files are up-to-date with respect to the input files.
Target _ResolveAndroidSigningKey:
Touching "obj/Debug/net8.0-android/android_debug_keystore.flag".
Target _Sign:
Skipping target "_Sign" because all output files are up-to-date with respect to the input files.
Target _Upload:
Using cached value from RegisterTaskObject
Found device: 35121JEHN14151
LastWriteTime of `/Users/jmather/Documents/PDI/Development/MauiPrototype/MauiApp4/MauiApp4/obj/Debug/net8.0-android/upload.flag`: 1/1/1601 12:00:00 AM
DEBUG RunShellCommand 35121JEHN14151 "run-as" "com.companyname.mauiapp4" "pwd" [4ms]
pwd returned: run-as: unknown package: com.companyname.mauiapp4
Package com.companyname.mauiapp4 was not installed.
DEBUG RunShellCommand 35121JEHN14151 "run-as" "com.companyname.mauiapp4" "files/.__tools__/xamarin.stat" "files/.__override__" [48ms]
files/.__tools__/xamarin.stat returned: run-as: unknown package: com.companyname.mauiapp4
DEBUG RunShellCommand 35121JEHN14151 "run-as" "com.companyname.mauiapp4" "rm" "-Rf" "files/.__override__" [45ms]
rm returned: run-as: unknown package: com.companyname.mauiapp4
DEBUG RunShellCommand 35121JEHN14151 rm "/data/local/tmp/com.companyname.mauiapp4-Signed.apk" [128718ms]
1>Xamarin.Android.Common.Debugging.targets(678,5): Error ADB1000 : Mono.AndroidTools.AdbException: Attempted to read past the end of the stream.
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at Mono.AndroidTools.Util.ReadFullAsyncResult.EndRead(IAsyncResult ar) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Util/StreamExtensions.cs:line 93
at Mono.AndroidTools.Adb.AdbSyncClient.FileWrite_OnReadStatus(IAsyncResult ar) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Adb/AdbSyncClient.cs:line 619
--- End of inner exception stack trace ---
at Mono.AndroidTools.Util.AggregateAsyncResult.CheckError(CancellationToken token) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Util/AggregateAsyncResult.cs:line 70
at Mono.AndroidTools.Adb.AdbSyncClient.EndPush(IAsyncResult result) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Adb/AdbSyncClient.cs:line 770
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location ---
at AndroidDeviceExtensions.PushAndInstallPackageAsync(AndroidDevice device, PushAndInstallCommand command, CancellationToken token) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Xamarin.AndroidTools/Devices/AndroidDeviceExtensions.cs:line 215
at AndroidDeviceExtensions.PushAndInstallPackageAsync(AndroidDevice device, PushAndInstallCommand command, CancellationToken token) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Xamarin.AndroidTools/Devices/AndroidDeviceExtensions.cs:line 242
at Xamarin.Android.Tasks.FastDeploy.InstallPackage(Boolean installed) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 381
at Xamarin.Android.Tasks.FastDeploy.InstallPackage(Boolean installed) in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 399
at Xamarin.Android.Tasks.FastDeploy.RunInstall() in /Users/runner/work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 248
C# detected
The app itself is a brand new .NET 8 MAUI app created in JetBrains Rider 2023.3.3. The only change is that I added <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
to the project file.
I tested USB deployment on three Macs:
@dellis1972
I tried to collect the logs, but there is no Install
target:
% dotnet build ./MauiApp4.csproj -t:Install -p:_FastDeploymentDiagnosticLogging=true -bl
MSBuild version 17.8.3+195e7f5a3 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
/Users/jmather/Documents/PDI/Development/MauiPrototype/MauiApp4/MauiApp4/MauiApp4.csproj : error MSB4057: The target "Install" does not exist in the project.
Build FAILED.
I tried other targets based on the build output in Rider, but nothing worked.
A couple other findings...
Found device
, Error ADB1000
also occurs when I unplug the USB cable or I restart adb. So the crash itself is most likely a symptom of the adb connection terminating.Sorry, forgot this is a maui app. We need to specify the framework with the -f
dotnet build <your project> -t:Install -p:_FastDeploymentDiagnosticLogging=true -bl -f net8.0-android
(or net7.0-android if you are using that).
Also, have you tried the Wifi Debugging option on Android? That seemed to help others.
@dellis1972
Log file available here. (The file is 53mb, which is too big to upload into the discussion thread.)
Wifi debugging works sporadically with the Pixel 5a, but doesn't work at all with the Pixel 7a. I factory reset the Pixel 5a and nothing improved regarding USB or wireless debugging.
One interesting note is that if I delete the bin/obj folders, then use the build command you provided, installation to the device works 50% of the time. But if bin/obj pre-exist, installation never works.
The build command I'm using is:
dotnet build ./MauiApp4.csproj -t:Install -p:_FastDeploymentDiagnosticLogging=true -f net8.0-android -v:diag > build.log
Thanks for your help!
Okay, this is probably just me, but had the same symptoms, the deploy was just hanging...
On a whim, I changed from plugging my phone into a crappy usb hub, and directly into a powerful usb c docking station, and voila, my app starts debugging from Rider...
At least something to try... Especially if wifi debugging works, i would double and triple check the usb cabled setup...
Was there any update to this? Wifi debugging is painfully slow. I double checked cords as @tompi mentioned, doesn't seem to change anything.
Are more build logs required, or is this a known issue being worked on.
If you are asking about the forever hang, that has been looked at. The problem seems to be with the underlying adb client which we have no control over. So a back up was put in place to detect such a hang and fall back to a slightly slower method of deployment.
Having a decent USB cable has always been an important part of debugging on devices for android. Some usb cables are not not very good quality and probably produce too many noise when sending data (resulting in errors). These cheaper cables are good for charging, but not for reliable data transfer, as @tompi mentioned.
How slow is the slow method expected to be for a file > new project? I have .NET and MAUI updated it still never deployed.
Is there any way I can confirm from my end that it is falling back to the slower method?
You can try setting the following MSBuild property _FastDeploymentDiagnosticLogging
to true when deploying from the command line.
dotnet build foo.csproj -f net8.0-android -p:_FastDeploymentDiagnosticLogging=true -bl
This will output a diagnostic build log with some additional text.
I would not advice using _FastDeploymentDiagnosticLogging
in the project directly since it is likely to cause VS some issues as it produces so much data.
Hey @dellis1972 , finally got some time to try this again.
tl;dr; seems to work now with no changes I got through about 1-2 deploys and it has suddenly stopped deploying from Rider again.
I was able to build and deploy with
dotnet build MediaGalleryTest.csproj.csproj -f net8.0-android -p:_FastDeploymentDiagnosticLogging=true -bl
That generated this binlog. msbuild.binlog.zip
I got MSBuild Structured Log Viewer for macOS and I was able to open the binlog but I don't really know what I am looking for in there. For future reference what would I be looking for in there?
Back to back builds (deleting app from device, deleting bin/obj, not using -bl
) I am getting large variations in build times. Some 55sec, some 1min 30sec. Is this odd behaviour?
Building and deploying in release mode in VS4Mac took about 3min 10sec. It did deploy, but it didn't start. I forgot to write down the error.
Building and deploying in debug mode in VS4Moac took 1min 20sec, and debugging appears to start correctly.
Changing some of the code in MainPage.xaml.cs
and debugging again only took about 10sec for it to be running again. This was the only build I didn't delete bin/obj/app.
Jumping over to Rider where I was for my previous comments it took 1min 58sec to debug a fresh build, 20sec for a build after an edit. In my above comments with Rider it took far longer than 2 mins. I had time to go to the toilet and make a coffee and when I had come back it was still sitting. Unsure why it is working now 🤷♂️
EDIT: Has gone back to not deploying anymore. Not entirely sure why it was working back to back and then it suddenly stopped. Closing Rider, deleting bin/obj (but not app) and running
dotnet build MediaGalleryTest.csproj -f net8.0-android -t:Install
resulted in no devices found. Unsure if closing Rider closed adb service.
Did
adb devices
and it started adb again, listed my devices. Built and deployed app, but now it won't launch. Hangs on splash screen.
Uninstalling app from phone and trying again, deleting bin/obj as well and now trying to build from terminal again
/Users/beeradmoore/RiderProjects/MediaGalleryTest/MediaGalleryTest/Platforms/Android/AndroidManifest.xml : error APT2260: resource style/Maui.SplashTheme (aka com.companyname.mediagallerytest:style/Maui.SplashTheme) not found. [/Users/beeradmoore/RiderProjects/MediaGalleryTest/MediaGalleryTest/MediaGalleryTest.csproj::TargetFramework=net8.0-android]
Maybe this is the universes way of telling me that I'm just not meant to make Android apps anymore 😂
@beeradmoore
It is using the backup path. In your log I see
'xamarin.sync' returned 'error: Could not read data from stdin. The operation timed out. [5173251192] ' when deploying 'files/.__override__/Xamarin.Google.Crypto.Tink.Android.dll'. Falling back to backup deployment.
It does sound like an adb
issue , I'm not entirely sure how to go about fixing that though since its a google tool.
EDIT: Current workaround. Ensure adb server is not running (reboot your machine). Open termianl and adb server as a forground process
adb nodaemon server
Now open your IDE and go work. So far (at least from my minimal testing) this appears to work. If this is true then I think the problem is not adb, but how IDEs are launching adb OR the permission scope that process launched within terminal has.
======
I have another update which might shine light on the underlying problem.
Just got a new MacBook, doing setup I didn't install VS4Mac. I installed mono, Xamarin.Android/iOS manually, and then installed Rider to use as my IDE.
Trying to debug a Xamarin.Forms app to Android and I get the same issue. When I tried to deploy from terminal it also hung, but then I closed Rider and the terminal had an error. I guess this is the adb server shutting down because Rider quit. Running the exact same line by hitting up and enter, I was able to delpoy just fine. Opening Rider I could also deploy fine. I think there may be an issue with how Rider (and VS4Mac) start adb
. Maybe user permissions of the executable, or file access or something? Anyway, below is the full set of testing I did.
When I open Rider (and by this I mean my Xamarin.Forms project) the notifications panel says,
* daemon not running; starting now at tcp:5037
* daemon started successfully
I assume this is because adb server is not running so it starts it. When I try debug it hangs, console says this.
Signed android package 'bin/Debug/com.beeradmoore.myapp-Signed.apk'
Target _Upload:
Using cached value from RegisterTaskObject
Found device: 804KPED1804588
I opened terminal and went to bin/Debug/
and then ran
adb install com.beeradmoore.myapp-Signed.apk
This also hangs with this message,
Performing Streamed Install
This is when I quit Rider and the terminal exit the above command with this error
adb: failed to install com.beeradmoore.myapp-Signed.apk
This is what I was saying about how I think this is Rider killing the adb server that it started with daemon not running; starting now
.
I hit up and enter on my terminal to run adb install
again, and this time it said this,
* daemon not running; starting now at tcp:5037
* daemon started successfully
Performing Streamed Install
Success
Performing Streamed Install
to Success
took about 6 seconds.
I opened Rider again, notifications did not mention the daemon
so I assume its using the adb server from terminal so it doesn't need to add it.
I quit Rider, I quit terminal, and I deleted bin/Debug/
directory.
I then opened Rider again and got the
* daemon started successfully
* daemon not running; starting now at tcp:5037
and I once again can't deploy. I was then able to repeat the above to deploy from termianl first to then fix things.
In all of this EmbedAssembliesIntoApk
is set to true. When I removed it from my csproj and went through the above steps to get into a working state again I was able to deploy from Rider in about 30 seconds.
At some point Rider did say that it then started adb daemon after I navigated away in termianl and went and did other things. Maybe some timeout thing?
EDIT: I was curious if I can make adb as a forground process, turns out yes!
adb nodaemon server
Minimal testing, but so far it appears I can run this and then run Rider and deploy successfully. In theory this will not be killed for being idle like above. I think this is currently the best workaround if it works for other people.
@beeradmoore very interesting investigation.
I suspect mode of the IDE's and CLI's are just calling the adb
exe without any special arguments. As a result it always starts in daemon
mode. I guess they could do the equivelant of adb kill-server && adb nodaemon
. In my testing the nodaemon
will just run the exe in the current terminal. I'm not sure if the IDE's or the CLI's have been designed to keep the process around. They mostly just fire of adb
commands and let the daemon deal with if it needs to start up or use an existing instance.
@jonpryor @tondat any thoughts on this particular issue? specifically the info provided in https://github.com/dotnet/android/issues/9261
I think it would be more to detect if adb is running and if it isn't then then start it with nodaemon
rather than start-server
.
What I don't get with this though is why now, and why did it seem to work for Xamarin.Forms people earlier in the thread.
Unsure if it's an OS change, or a how/what Android SDK you have installed. Whatever it is it seems it isn't directly something VS4Mac is doing, or what Rider is doing, unless they both happen to start adb with the same broken set of permissions or something. I would not be shocked if this is some macOS security thing getting in the way. But again, why now, and why not everyone's project.
Something else thought of regarding permissions, what if I run as root:
If I do this,
open -na "Rider.app"
app does not deploy. However if I do this,
sudo open -na "Rider.app"
it seems to deploy fine 🤷♂️ (however looking in activity monitor, Rider, rider-backend, and adb all appear to be my user, not root. So I am even more confused now)
I don't have VS4Mac installed anymore but I assume
sudo open -na "Visual Studio for Mac.app"
may work for deployment there as well.
I wouldn't recommend that for everyday use though 😅
Description
I am not able to debug any Android App on device with .NET MAUI (latest workload 7.0.92);
Something is getting deployed to the device, but never starts. Starting manually results in an immediate crash. The deployment task hangs like forever at:
Every now and then it gets past that point, then I see a bunch of these errors:
Deploying a Xamarin.Forms app works without any problems! Deploying to the default Pixel 5 Android API 33 emulator works as well.
Steps to Reproduce
Create a new .NET MAUI App Hit the Debug button
Expected outcome: App gets deployed and debugging starts Actual outcome: Something gets deployed, but most of the time the process gets stuck. If it gets past that step, the above mentioned error is written multiple times in the output window.
Link to public reproduction project repository
-
Version with bug
Unknown/Other
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12 (unsure about others).
Did you find any workaround?
No
Relevant log output
No response