Skip to content

Commit 41edce4

Browse files
committed
[Xamarin.Android.Build.Tests] Add support for testing on system applications.
Context https://work.azdo.io/1288717 The new fast deployment system broke fast deployment for system installed applications. This commit adds unit tests to stop this kind of regression in the future. In order to install a `system` application we need a few things to happen 1. The emulator MUST be started with the `-system-writable` argument 2. The apk needs to be signed with a platform keystore. 3. The AndroidManifest must include `android:sharedUserId="android.uid.system"` in its `manifest` element.
1 parent 304e698 commit 41edce4

File tree

30 files changed

+231
-87
lines changed

30 files changed

+231
-87
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:main@75cf1a237380e95f684438b782e3829efc5109c6
1+
xamarin/monodroid:main@83de4b43c1de819f21c923bc3d6aeb37cc3949cd
22
mono/mono:2020-02@be9218f4d1f7529fbe85d15c58f6fe78161909b3

Documentation/guides/building-apps/build-properties.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,16 @@ To use a file located at `C:\Users\user1\AndroidSigningPassword.txt`:
10411041
> The `env:` prefix is not supported when [`$(AndroidPackageFormat)`](#androidpackageformat)
10421042
> is set to `aab`.
10431043
1044+
## AndroidSigningPlatformKey
1045+
1046+
Specifies the key file to use to sign the apk.
1047+
This is only used when building `system` applications.
1048+
1049+
## AndroidSigningPlatformCert
1050+
1051+
Specifies the certificate file to use to sign the apk.
1052+
This is only used when building `system` applications.
1053+
10441054
## AndroidSupportedAbis
10451055

10461056
A string property that contains a

Documentation/guides/messages/xa4310.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ ms.date: 03/09/2020
88
## Example messages
99

1010
```
11-
error XA4310: `$(AndroidSigningKeyStore)` file `filename.keystore` could not be found.
11+
error XA4310: `$(Property)` file `filename.keystore` could not be found.
1212
```
1313

1414
## Issue
1515

16-
The specified `$(AndroidSigningKeyStore)` file could not be located on disk.
16+
The specified `$(Property)` file could not be located on disk.
1717

1818
## Solution
1919

20-
Check that the `$(AndroidSigningKeyStore)` MSBuild property is set to a valid
21-
path of an existing keystore.
22-
23-
This property corresponds to the **Keystore** field in the **Android Package
24-
Signing** section of the Visual Studio project property pages.
20+
Check that the `$(Property)` MSBuild property is set to a valid
21+
path of an existing file.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### Application build and deployment
2+
3+
* [Developer Community 1288717][0]:
4+
*Support Fast Deployment for System Applications.*
5+
Added support for fast deployment while building system based
6+
applications. Applications developed in this mode need to be
7+
signed with a platform key and have a special attribute
8+
9+
`android:sharedUserId="android.uid.system"`
10+
11+
in the `AndroidManifest.xml`.
12+
13+
[0]: https://developercommunity.visualstudio.com/t/VS-2019-1690-Error-XA0130-XamarinAndr/1359238

build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/StartAndroidEmulator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class StartAndroidEmulator : Task
2020
public string AndroidSdkHome {get; set;}
2121
public string Port {get; set;}
2222
public string ImageName {get; set;} = "XamarinAndroidTestRunner64";
23+
public string Arguments {get; set;}
2324
public string ToolPath {get; set;}
2425
public string ToolExe {get; set;}
2526

@@ -62,7 +63,7 @@ void Run (string emulator)
6263
return;
6364

6465
var port = string.IsNullOrEmpty (Port) ? "" : $" -port {Port}";
65-
var arguments = $"-verbose -no-boot-anim -no-audio -no-snapshot -cache-size 512 -timezone \"Etc/UTC\" -avd {ImageName}{port}";
66+
var arguments = $"{Arguments ?? string.Empty} -verbose -no-boot-anim -no-audio -no-snapshot -cache-size 512 -timezone \"Etc/UTC\" -avd {ImageName}{port}";
6667
Log.LogMessage (MessageImportance.Low, $"Tool {emulator} execution started with arguments: {arguments}");
6768
var psi = new ProcessStartInfo () {
6869
FileName = emulator,

build-tools/automation/azure-pipelines-nightly.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ stages:
168168
- template: yaml-templates/run-timezoneinfo-tests.yaml
169169
parameters:
170170
node_id: 4
171+
172+
- template: yaml-templates/run-systemapp-tests.yaml

build-tools/automation/azure-pipelines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ variables:
6363
# - This is a non-fork branch with name containing "mono-" (for Mono bumps)
6464
IsMonoBranch: $[and(ne(variables['System.PullRequest.IsFork'], 'True'), or(contains(variables['Build.SourceBranchName'], 'mono-'), contains(variables['System.PullRequest.SourceBranch'], 'mono-')))]
6565
RunAllTests: $[or(eq(variables['XA.RunAllTests'], true), eq(variables['IsMonoBranch'], true))]
66-
DotNetNUnitCategories: '& TestCategory != DotNetIgnore & TestCategory != AOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger'
66+
DotNetNUnitCategories: '& TestCategory != DotNetIgnore & TestCategory != AOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger & TestCategory != SystemApplication'
6767
NUnit.NumberOfTestWorkers: 4
6868
GitHub.Token: $(github--pat--vs-mobiletools-engineering-service2)
6969
CONVERT_JAVADOC_TO_XMLDOC: $[ne(variables['Build.DefinitionName'], 'Xamarin.Android-PR')]

build-tools/automation/yaml-templates/run-msbuild-device-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
useDotNet: $(UseDotNet)
6161
testRunTitle: MSBuildDeviceIntegration On Device - macOS - ${{ parameters.job_suffix }}
6262
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/MSBuildDeviceIntegration/${{ parameters.target_framework }}/MSBuildDeviceIntegration.dll
63-
nunitConsoleExtraArgs: --where "cat != TimeZoneInfo && cat != SmokeTests ${{ parameters.nunit_categories }}"
63+
nunitConsoleExtraArgs: --where "cat != SystemApplication && cat != TimeZoneInfo && cat != SmokeTests ${{ parameters.nunit_categories }}"
6464
dotNetTestExtraArgs: --filter "TestCategory != TimeZoneInfo & TestCategory != SmokeTests ${{ parameters.nunit_categories }}"
6565
testResultsFile: TestResult-MSBuildDeviceIntegration-${{ parameters.job_name }}-$(XA.Build.Configuration).xml
6666

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Runs TimeZoneInfo tests against an emulator running on macOS
2+
3+
jobs:
4+
- job: mac_systemapp_tests
5+
displayName: System App Emulator Tests
6+
pool:
7+
vmImage: $(HostedMacImage)
8+
timeoutInMinutes: 120
9+
cancelTimeoutInMinutes: 5
10+
workspace:
11+
clean: all
12+
steps:
13+
- template: setup-test-environment.yaml
14+
15+
- script: mono $(System.DefaultWorkingDirectory)/build-tools/xaprepare/xaprepare/bin/$(XA.Build.Configuration)/xaprepare.exe --s=EmulatorTestDependencies --no-emoji --run-mode=CI
16+
displayName: install emulator
17+
18+
- task: DownloadPipelineArtifact@2
19+
inputs:
20+
artifactName: $(TestAssembliesArtifactName)
21+
downloadPath: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)
22+
23+
- task: MSBuild@1
24+
displayName: start emulator
25+
inputs:
26+
solution: tests/Mono.Android-Tests/Mono.Android-Tests.csproj
27+
configuration: $(XA.Build.Configuration)
28+
msbuildArguments: >-
29+
/t:AcquireAndroidTarget /p:TestEmulatorArguments=-writable-system /bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/start-emulator.binlog
30+
31+
- template: run-nunit-tests.yaml
32+
parameters:
33+
testRunTitle: System App On Device - macOS
34+
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/MSBuildDeviceIntegration/net472/MSBuildDeviceIntegration.dll
35+
nunitConsoleExtraArgs: --where "cat == SystemApplication"
36+
testResultsFile: TestResult-SystemApp--$(XA.Build.Configuration).xml
37+
38+
- task: MSBuild@1
39+
displayName: shut down emulator
40+
inputs:
41+
solution: tests/Mono.Android-Tests/Mono.Android-Tests.csproj
42+
configuration: $(XA.Build.Configuration)
43+
msbuildArguments: >-
44+
/t:AcquireAndroidTarget,ReleaseAndroidTarget
45+
/bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog
46+
condition: always()
47+
48+
- template: upload-results.yaml
49+
parameters:
50+
artifactName: Test Results - System App With Emulator - macOS
51+
52+
- template: fail-on-issue.yaml

build-tools/scripts/TestApks.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<StartAndroidEmulator
6666
Condition=" '$(_ValidAdbTarget)' != 'True' "
6767
AndroidSdkHome="$(AndroidSdkDirectory)"
68+
Arguments="$(TestEmulatorArguments)"
6869
ImageName="$(TestAvdName)"
6970
Port="$(_AdbEmulatorPort)"
7071
ToolExe="$(EmulatorToolExe)"

0 commit comments

Comments
 (0)