Skip to content

Commit 2a04748

Browse files
authored
[Xamarin.Android.Build.Tests] Add support for testing on system applications. (#5708)
Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288717 Context: xamarin/monodroid@83de4b4 The new fast deployment system (xamarin/monodroid@767f6471) broke fast deployment for system-installed applications. This is fixed in xamarin/monodroid@83de4b43. 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
1 parent d9ed129 commit 2a04748

File tree

30 files changed

+265
-88
lines changed

30 files changed

+265
-88
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,20 @@ 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+
Support for this property was added in Xamarin.Android 11.3.
1050+
1051+
## AndroidSigningPlatformCert
1052+
1053+
Specifies the certificate file to use to sign the apk.
1054+
This is only used when building `system` applications.
1055+
1056+
Support for this property was added in Xamarin.Android 11.3.
1057+
10441058
## AndroidSupportedAbis
10451059

10461060
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
@@ -173,3 +173,5 @@ stages:
173173
- template: yaml-templates/run-timezoneinfo-tests.yaml
174174
parameters:
175175
node_id: 4
176+
177+
- 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)"

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,10 @@ The following are literal names and should not be translated: ABI, 'libs/armeabi
712712
<comment>The following are literal names and should not be translated: MultiDexMainDexList</comment>
713713
</data>
714714
<data name="XA4310" xml:space="preserve">
715-
<value>`$(AndroidSigningKeyStore)` file `{0}` could not be found.</value>
716-
<comment>The following are literal names and should not be translated: `$(AndroidSigningKeyStore)`</comment>
715+
<value>`{0}` file `{1}` could not be found.</value>
716+
<comment>{0} - The MSBuildProperty which contains the file name value.
717+
{1} - The value of the MSBuildProperty. Normally a filename.
718+
</comment>
717719
</data>
718720
<data name="XA4311" xml:space="preserve">
719721
<value>The application won't contain the paired Wear package because the Wear application package APK is not created yet. If building on the command line, be sure to build the "SignAndroidPackage" target.</value>

0 commit comments

Comments
 (0)