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

[Xamarin.Android.Build.Tests] Add support for testing on system apps (#5708) #5791

Merged
merged 2 commits into from
Mar 30, 2021

Commits on Mar 29, 2021

  1. [Xamarin.Android.Build.Tests] Add support for testing on system appli…

    …cations. (dotnet#5708)
    
    Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288717
    Context: xamarin/monodroid@83de4b4
    
    Changes: xamarin/monodroid@b2a750a...4163ee9
    
      * xamarin/monodroid@4163ee947: [Xamarin.Android.Build.Tasks] Support FastDev for System Apps (dotnet#1177) (dotnet#1186)
      * xamarin/monodroid@947c6ef72: Bump to xamarin/xamarin-android/d16-9@877f5727 (dotnet#1183)
    
    The new fast deployment system (xamarin/monodroid@767f6471) broke
    fast deployment for system-installed applications.
    
    This is fixed in xamarin/monodroid@4163ee94.
    
    Adds unit tests to stop this kind of regression in the future.
    
    In order to install a `system` application we need a few things:
    
     1. The emulator MUST be started with the `-system-writable` argument
    
     2. The `.apk` needs to be signed with a platform keystore, found at:
        https://github.com/aosp-mirror/platform_build/tree/master/target/product/security
    
     3. `AndroidManifest.xml` must set
        [`/manifest/@android:sharedUserId`][0] to `android.uid.system`:
    
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                android:sharedUserId="android.uid.system"
                …>
            </manifest>
    
    See also:
    
      * https://medium.com/xrpractices/android-system-apps-development-d73bedfb8def
    
    [0]: https://developer.android.com/guide/topics/manifest/manifest-element#uid
    dellis1972 authored and jonpryor committed Mar 29, 2021
    Configuration menu
    Copy the full SHA
    3d6aa6a View commit details
    Browse the repository at this point in the history

Commits on Mar 30, 2021

  1. [Xamarin.ProjectTools] fix toggling XamarinProject.IsRelease (dotnet#…

    …5571)
    
    Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4422361&view=ms.vss-test-web.build-test-results-tab&runId=18547936&resultId=100086&paneView=debug
    
    We had an MSBuild test failing under .NET 6:
    
        MSBuildDeviceIntegration On Device - macOS - One .NET > SwitchConfigurationsShouldRedeploy
        fastdev directory should NOT exist for Release builds.
        Expected string length 0 but was 4970. Strings differ at index 0.
        Expected: <string.Empty>
        But was:  "Java.Interop.dll\nMicrosoft.CSharp.dll\nMicrosoft.VisualBasic.C..."
    
    This was because a supposed `Release` build was skipping the `_Upload`
    target completely:
    
        Skipping target "_Upload" because all output files are up-to-date with respect to the input files.
        Input files: bin\Debug\UnnamedProject.UnnamedProject-Signed.apk...
    
    It appears that toggling `XamarinProject.IsRelease` is not triggering
    the correct files to save when the tests run under .NET 6.
    
    Under "legacy" Xamarin.Android, the tests simply put this at the top
    of the `.csproj`:
    
          <Configuration>Debug</Configuration>
        ...
        <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
    
    This won't work in short-form MSBuild projects, because the `.csproj`
    is effectively:
    
        <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
        ...
          <Configuration>Debug</Configuration>
        ...
        <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
    
    For things to work properly, we need `$(Configuration)` to be set
    *before* `Microsoft.NET.Sdk/Sdk.props`.
    
    So we put `$(Configuration)` in a `Directory.Build.props` to solve
    this ordering problem. Unfortunately, we were not calling `Touch()` on
    this file when `XamarinProject.IsRelease` changes.
    
    After making this change, `SwitchConfigurationsShouldRedeploy` passes.
    jonathanpeppers authored and jonpryor committed Mar 30, 2021
    Configuration menu
    Copy the full SHA
    5a33b14 View commit details
    Browse the repository at this point in the history