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

Conversation

jonpryor
Copy link
Member

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288717
Context: https://github.com/xamarin/monodroid/commit/83de4b43c1de819f21c923bc3d6aeb37cc3949cd

Changes: https://github.com/xamarin/monodroid/compare/b2a750a2bd9f25e4f16592168dd919bf36930de4...4163ee94735f4176d2e212041d15c9158316371e

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 to android.uid.system:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        android:sharedUserId="android.uid.system"
        …>
    </manifest>
    

See also:

…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
…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.
@jonpryor jonpryor merged commit b83dd4d into dotnet:d16-9 Mar 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants