dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

Shared runtime redeployed on overy run #3091

Closed MichalSznajder closed 5 years ago

MichalSznajder commented 5 years ago

When I run my application in Debug shared runtime is constantly deployed to my target device. Application is actually Xamarin.Forms but I think it does not matter here.

I did run msbuild in verbose mode and below is interesting part. It look like build process is not able to veryfiy that shared runtime is installed and redeploys shared runtime every time.

I use Huavei P20 Pro with Oreo on board. Other software versions below.

[BEGIN] Detecting installed packages
[MESSAGE] Detecting installed packages...
  Detecting installed packages... (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 am broadcast -a "mono.android.intent.action.PACKAGE_VERSIONS" -e "packages" "Mono.Android.DebugRuntime,Mono.Android.Platform.ApiLevel_27,com.myapp.app" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.PackageVersions" (TaskId:597)

  TASK: Broadcast 
  am broadcast -a "mono.android.intent.action.PACKAGE_VERSIONS" -e "packages" "Mono.Android.DebugRuntime,Mono.Android.Platform.ApiLevel_27,com.myapp.app" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.PackageVersions" 

  completed?:Broadcasting: Intent { act=mono.android.intent.action.PACKAGE_VERSIONS flg=0x400000 cmp=Mono.Android... (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 cat /data/system/packages.xml (TaskId:597)
  TASK: GetPackages cat /data/system/packages.xml completed?:cat: /data/system/packages.xml: Permission denied
   (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 cat /dbdata/system/packages.xml (TaskId:597)
  TASK: GetPackages cat /dbdata/system/packages.xml completed?:cat: /dbdata/system/packages.xml: No such file or directory
   (TaskId:597)
[BEGIN] Removing old runtime
[MESSAGE] Removing old runtime: Mono.Android.DebugRuntime...
  Removing old runtime: Mono.Android.DebugRuntime... (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 pm uninstall "Mono.Android.DebugRuntime" (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 pm uninstall "Mono.Android.DebugRuntime" (TaskId:597)
  TASK: UninstallPackage pm uninstall "Mono.Android.DebugRuntime" completed?:Failure [DELETE_FAILED_INTERNAL_ERROR]
   (TaskId:597)
[END] 
[BEGIN] Installing shared runtime
[MESSAGE] Target device is arm64-v8a.
  Target device is arm64-v8a. (TaskId:597)
[MESSAGE] Installing the Mono shared runtime (debug - 1549073043)...
  Installing the Mono shared runtime (debug - 1549073043)... (TaskId:597)
  TASK: UninstallPackage pm uninstall "Mono.Android.DebugRuntime" completed?:Success
   (TaskId:597)
[PROGRESS] 10
  10% ... 3456kb of 34475kb copied (TaskId:597)
Version 15.9.11
VisualStudio.15.Release/15.9.11+28307.586
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Professional

Xamarin   4.12.3.83 (d15-9@23fa80172)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   9.1.7.0 (HEAD/ba9da7a76)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   12.4.0.64 (9c8d8e0)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
dellis1972 commented 5 years ago

@michalsznajder looks like a permissions issue

  TASK: GetPackages cat /data/system/packages.xml completed?:cat: /data/system/packages.xml: Permission denied
   (TaskId:597)
  DEBUG RunShellCommand LCL0218730001137 cat /dbdata/system/packages.xml (TaskId:597)
  TASK: GetPackages cat /dbdata/system/packages.xml completed?:cat: /dbdata/system/packages.xml: No such file or directory
   (TaskId:597)

do either of those files exist on the device?

pulimento commented 5 years ago

@dellis1972 it's not a permissions problem. AFAIK, none of the stock Android devices have this file user-readable.

I have the same issue, I think the problem is that the "am broadcast" command is considering that Mono runtime packages are not installed. The mechanism to detect if the runtime packages are installed is failing.

Device: OnePlus, stock Android 9.0. Not ocurring on simulators. Visual Studio Enterprise 16.3.2 Xamarin 16.3.0.274 Xamarin Android SDK 10.0.0.43

I'm attaching here the text and binary log msbuild ImageTestXamarin.Android.csproj /t:SignAndroidPackage;Install /bl /v:diag > output.txt XamForms-3091-text-and-binary-log.zip

Each time you debug and deploy the app to a device, it keeps constantly reinstalling Mono Runtime and API 28 plaform runtime

EDIT: Added a video, showing that behavior (phone plugged, and every time I deploy, it reinstall the shared runtime), The video shows Visual Studio info, and adb shell command output. https://www.youtube.com/watch?v=Fb7wLoMHV-c

Command: adb shell am broadcast -a "mono.android.intent.action.PACKAGE_VERSIONS" -e "packages" "Mono.Android.DebugRuntime,Mono.Android.Platform.ApiLevel_28,com.companyname.imagetestxamarin" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.PackageVersions" Output: Broadcasting: Intent { act=mono.android.intent.action.PACKAGE_VERSIONS cmp=Mono.Android.DebugRuntime/com.xamarin.mono.android.PackageVersions (has extras) } , data="Mono.Android.DebugRuntime=1565368993,Mono.Android.Platform.ApiLevel_28=1570442517,com.companyname.imagetestxamarin=1"

Binary log video: https://www.youtube.com/watch?v=BCNkgAvS-nM

dellis1972 commented 5 years ago

@pulimento thanks for the data. I'll ask our team to see if we have a OnePlus with stock 9.0 on it, hopefully we can repo.

pulimento commented 5 years ago

@dellis1972 just updated my original comment. I've recorded a screen record with the phone plugged in. Just checked on android simulators and works as expected, so it's a device only issue.

dellis1972 commented 5 years ago

@pulimento cool. Thanks for the info. Looking at the logs it does seem to have trouble uninstalling the previous version of the Shared Runtime. Do you still get the issue if you manually uninstall the version that is on the phone?

pulimento commented 5 years ago

@dellis1972 problem happens because is trying to uninstall it twice (really, the runtime, already installed, is installed again, and, at the end, it gets installed again)

Please see this video, walking the binary log of my original comment: https://www.youtube.com/watch?v=BCNkgAvS-nM

dellis1972 commented 5 years ago

@pulimento I understand what the issue is. I was just wondering what happened if you manually uninstall the Shared Runtime? It could be its just a bad install or the package is in a state that adb cannot uninstall it (that does happen from time to time)

pulimento commented 5 years ago

@dellis1972 I can uninstall it just fine:

image

dellis1972 commented 5 years ago

Hmm, ok thanks for testing.

dellis1972 commented 5 years ago

@pulimento hi, it looks like we have managed to reproduce the issue on a OnePlus device. Our team is now investigating.

pulimento commented 5 years ago

Oh nice! Please let me know if I can help. Thanks

El mar., 8 oct. 2019 18:40, Dean Ellis notifications@github.com escribió:

@pulimento https://github.com/pulimento hi, it looks like we have managed to reproduce the issue on a OnePlus device. Our team is now investigating.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xamarin/xamarin-android/issues/3091?email_source=notifications&email_token=AAD24ENBSRBVKKHRBULAFJDQNSZXHA5CNFSM4HMNFZB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAU2FXQ#issuecomment-539599582, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD24EIL7QNZUQKX6BLPHM3QNSZXHANCNFSM4HMNFZBQ .

pulimento commented 5 years ago

Sorry @dellis1972 why are you closing this? Any news?

dellis1972 commented 5 years ago

@pulimento GitHub auto closes issues when are PR which fixes that issue is merged. My colleague @pjcollins found the issue and has submitted a fix. We will work to get this into the next available preview as soon as well can.

dellis1972 commented 5 years ago

It turns out that not all android devices respond to a broadcast in the same manner. We were expecting something like "Broadcast completed: result=0" but were getting results like "data=\"\" completed: result=0" one certain devices. So we needed to update our code to handle these different results.

pulimento commented 5 years ago

fantastic! so it will ship with the next VS preview release?

dellis1972 commented 5 years ago

We missed the code checkin deadline for d16-4 Preview 2 :(, but we will make sure this gets into Preview 3.

MichalSznajder commented 5 years ago

I just noticed that you are working on it.

In my case I solved this by disabling aggressive power management available on my phone (Huawei P20 Pro). On my phone those broadcasts seen in my log returned nothing. Once I allowed background work on Xamarin packages in settings it was all OK. I think it was "Mono Shared Runtime" that was involved.

brendanzagaeski commented 4 years ago

Release status update

A new Preview version has now been published that includes the candidate improvement for this item for the cases where devices return different text in the broadcast reply than was previously expected. This improvement will not yet help for situations where the device is set to prevent background work by the Mono Shared Runtime package.

The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.1.0.29.

Fix included on Windows in Visual Studio 2019 version 16.4 Preview 3. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.4 Preview 2. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

brendanzagaeski commented 4 years ago

Release status update

A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix.

Fix included in Xamarin.Android 10.1.0.30.

Fix included on Windows in Visual Studio 2019 version 16.4. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

(Fix also included on macOS in Visual Studio 2019 for Mac version 8.4 Preview 2.1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)

andycted commented 4 years ago

I have VS 16.4.1 on Windows with Xamarin.Android SDK 10.1.1.0 (d16-4/f2c9364) Xamarin.Android Reference Assemblies and MSBuild support. Mono: bef1e63 Java.Interop: xamarin/java.interop/d16-4@c4e569f ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

It still does the same every time I deploy.

angusbreno commented 4 years ago

I can't debug/deploy one app!

The same everytime, hangs hangs and hangs... image

PLEASE Fix

brendanzagaeski commented 4 years ago

@andycted, @angusbreno, thanks for the new information! When you get a chance, if you could submit new issues with the descriptions of what you're seeing so the team can take a look, that would be perfect.

andycted commented 4 years ago

What I’m seeing is exactly the same issue described in this thread. So why should I open a new one ? I can only tell you that your fix didn’t work at all.

brendanzagaeski commented 4 years ago

@andycted, I'd recommend a new issue mostly just to help ensure your symptom gets the proper visibility with the team for further investigation, and to make sure it's clearly distinguished from the first fix that was added around shared runtime redeployments on this issue (for OnePlus devices).

If you like, I can open a new issue for you and copy and paste over your comment as a starting place. In that case, as a first little question, I'd be curious to know if you see the same behavior as michalsznajder mentioned.

That is, are you seeing the problem on a device where aggressive power management options are available and enabled? Thanks in advance!

michalsznajder commented on Oct 10 https://github.com/xamarin/xamarin-android/issues/3091#issuecomment-540913097

In my case I solved this by disabling aggressive power management available on my phone (Huawei P20 Pro). On my phone those broadcasts seen in my log returned nothing. Once I allowed background work on Xamarin packages in settings it was all OK.

angusbreno commented 4 years ago

I have VS 16.4.1 on Windows with Xamarin.Android SDK 10.1.1.0 (d16-4/f2c9364) Xamarin.Android Reference Assemblies and MSBuild support. Mono: bef1e63 Java.Interop: xamarin/java.interop@c4e569f ProGuard: xamarin/proguard@905836d SQLite: xamarin/sqlite@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools@9f4ed4b

It still does the same every time I deploy.

Same thing here, there is no related power options, cause i'm running on my galaxy s9+ with full processor power...

It hangs, on deploy. Simple as that.

I will open a new issue tomorrow with diagnostics, but please take a look, too many people with the same problem. In the previus VS version didnt happen this.

I'm responsible for +20 apps and i can't run debug anymore, it's despair.

andycted commented 4 years ago

@brendanzagaeski please do open a new issue.

I don't have power management issues or configurations. I do have the problem mentioned in the title. It sometimes hangs on deploy, but mostly, it takes forever to deploy the shared runtime each time.

The os version is on 4.4, it's a huawei y635-l21 I can give you more info if needed.

brendanzagaeski commented 4 years ago

Release status update

A new Release version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.1.1.0.

Fix included on macOS in Visual Studio 2019 for Mac version 8.4. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.4 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)