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

When using FastDeployment get error message XA0136: The 'run-as' command failed with 'run-as: Package 'packagename' has corrupt installation #7821

Open
jlinker7 opened this issue Feb 22, 2023 · 17 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@jlinker7
Copy link

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Windows VS 2020 Latest release (including Beta version), Android 7.1.1 Custom Device

Description

While trying the work around for issue #7521 (comment), which involves using Fast Deployment, I encounter the error

XA0136: The 'run-as' command failed with 'run-as: Package 'packagename' has corrupt installation'.
The currently installation of the package in corrupt. Please manually uninstall the
package from all the users on device and try again. If that does not work you can disable Fast Deployment.
Fast Deployment can be disabled in the Visual Studio project property pages or edit the project file in a text editor and set the 'EmbedAssembliesIntoApk' MSBuild property to 'true'.

msbuild.zip

Steps to Reproduce

  1. Xamarin.Android project running on custom device, Android 7.1.1, armv7 chip
  2. Visual Studio 2022 17.5.0 Preview 6.0 (but also experienced in on previous versions)
  3. Currently there is a bug that is preventing from running with debugger (mscorblib cannot load) that has a fix that isn't released yet, the work around is to use Fast Deployment
  4. Run with debug and Fast Deployment enabled
  5. Observe error about run-as command failed due to corrupt installation
  6. Without Fast Deployment, the app will start then crash due to the mscorlib error, but then you can relaunch the app without debugger and it runs fine
  7. With fast deployment, even after the initial attempt at it running, trying to run it again will result in an immediate crash

Did you find any workaround?

No

Relevant log output

XA0136: The 'run-as' command failed with 'run-as: Package 'packagename' has corrupt installation'.
The currently installation of the package in corrupt. Please manually uninstall the 
package from all the users on device and try again. If that does not work you can disable Fast Deployment.
Fast Deployment can be disabled in the Visual Studio project property pages or edit the project file in a text editor and set the 'EmbedAssembliesIntoApk' MSBuild property to 'true'.

Also attached msbuild.binlog.
@jlinker7 jlinker7 added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Feb 22, 2023
@dellis1972 dellis1972 assigned dellis1972 and unassigned grendello Feb 22, 2023
@dellis1972 dellis1972 added Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author. and removed Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Feb 22, 2023
@ghost
Copy link

ghost commented Feb 22, 2023

Hi @jlinker7. We have added the "need-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
Copy link
Contributor

@jlinker7

Thanks for opening the issue and the binlog.
However we are missing the additional diagnostics produced by the _FastDeploymentDiagnosticLogging option.
Could you please provide a new one with that option enabed?

msbuild foo.csproj /restore -t:Install -p:_FastDeploymentDiagnosticLogging=true -bl

@jlinker7
Copy link
Author

msbuildoutput_and_binlog.zip

My apologies, I thought I had it enabled before that run, but may have switched branches without realizing it. Let me know if this includes the information needed. I included both the binlog file and the output to the command prompt window when running the msbuild command. Thanks!

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

@jlinker7

can you try running the following command from the "Adb Command Prompt"

 adb shell pm uninstall com.lathem.payclock

Note we are not using the -k option which preserves data. I just wonder if there is something from a previous installation which didn't work. Also out of interest, has this ever worked?

@jlinker7
Copy link
Author

@dellis1972 I ran that command to uninstall it, then tried again with Fast Deployment and still get the same error.

To be honest, I cannot remember for sure if it ever worked, I don't think it has, but I have been working on this project for a few years now, and running it without Fast Deployment was working (until I switched to VS 2022) so that is what I have used, I think when I have tried Fast Deployment in "recent" memory it hasn't worked, but I cannot say for certain if it did or di not in the early days of the project.

@jlinker7
Copy link
Author

@dellis1972 For testing, I just created a brand new Xamarin.Android test app in visual studio 2022, with both the minimum and target android version set as 7.1, but the compile version set to Android 13.0 (same set up as the app I am working on), and get the same error.

@dellis1972
Copy link
Contributor

@jlinker7

It might be that this means something about run-as is just not working on that particular OS. If that is the case I'm not sure what we can do about it. Digging into the internals of the Android OS to figure out why it thinks the package is corrupt might be a bit of a task in itself. The error message you are seeing does not seem to appear in the current run-as code which is in https://github.com/aosp-mirror/platform_system_core/blob/master/run-as/run-as.cpp.

Unless there is a way to create an emulator image of that custom OS that you are using?

All that said, I might be able to detect this error message and do something else. The problem is run-as is the way we get access to the internal app files structure, since it is protected. So I'm not sure how we can get files in the place they need to be. This PR might work #5775, but its not a very nice solution because it leaves files around in tmp after the app is deleted.

@jlinker7
Copy link
Author

@dellis1972 Is the presumed issue to be file access? Or possibly missing directories? What folder structure is run-as needing access to? I can look and see if I can add directories as needed, or elevate permissions on directories if you think that would help?

@jlinker7
Copy link
Author

Logcat.txt
@dellis1972 Not sure if it is helpful, but here is the logcat from the device when trying fast deployment with the test app.

@dellis1972
Copy link
Contributor

I don't know enough about the internals of the Android OS to know what run-as it looking for or how it decides if something is corrupt. What we need to do I guess is somehow track down the code that your OS is using and take a look.

@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 Mar 10, 2023
@ghost
Copy link

ghost commented Mar 10, 2023

Hi @jlinker7. We have added the "need-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
Copy link
Contributor

@jlinker7

Do you have any details on the custom OS you are using? It would be nice to maybe try to create a VM or something which repo's the issue

@jlinker7
Copy link
Author

@dellis1972 Sadly, very little information. Its based of Stock Android 7.1 as far as I know. It does not include Google Play Services. They added a custom back button to the WiFi settings screen to return it to our app. They did the same for Ethernet Settings. They added a few intents we can push to enable or disable the navigation bar and a custom intent to trigger a reboot. They have never shared the repository with us though.

I tried to look through the Android Source code to figure out what run-as relies on so I could check the device to see if something was missing, but the code base is so massive I was not able to find anything quickly.

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

Looking back though the old source code we find this

https://github.com/aosp-mirror/platform_system_core/blob/nougat-mr1-release/run-as/run-as.c#L176

/* check that the data directory path is valid */
if (check_data_path(info.dataDir, userAppId) < 0) {
    panic("Package '%s' has corrupt installation\n", pkgname);
}

Which leads us to https://github.com/aosp-mirror/platform_system_core/blob/nougat-mr1-release/run-as/package.c#L217.

Which suggests there is something wrong with the data directory

@jlinker7
Copy link
Author

@dellis1972 Thank you for pointing me in the direction of that code, next chance I have I will look through it and see if I can verify each of those checks on the device. A cursory glance looks like permissions/ownership issues, or the directory is a simlink instead of real. Does this mean that deploying without Fast Deploy does not do the same check, as it seems deploying with or without Fast Deploy shouldn't affect the directory permissions or structure. When I get a chance to look more closely I will comment back here with my findings.

@dellis1972
Copy link
Contributor

@jlinker7

Normal installaton does not use run-as. For fast deployment we have to use run-as to gain access to the internal files directory so we can place the changed assemblies there. This is what speeds up the dev process.

A normal install the assemblies are packaged in the apk so it never hits this "path". But it does reduce development times since the apk has to be built and installed each time. With Fast dev we can just send the changed dll`s over and not touch the apk.

@jlinker7
Copy link
Author

@dellis1972 Ok, so since it doesn't use this directory when Fast Deployment is off, then it wouldn't run this check. Looking through the code I am leaning towards it being a permissions/ownership type issue. But have not quite figured out how to verify that.

@jpobst jpobst removed the need-attention A xamarin-android contributor needs to review label Mar 20, 2024
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.
Projects
None yet
Development

No branches or pull requests

4 participants