From d4428741ed0be7ae741f8457e149c1ccac3073fc Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 8 Mar 2021 13:30:13 +0000 Subject: [PATCH 1/2] [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. --- .external | 2 +- .../guides/building-apps/build-properties.md | 10 ++++ Documentation/guides/messages/xa4310.md | 11 ++-- Documentation/release-notes/5708.md | 13 +++++ .../StartAndroidEmulator.cs | 3 +- .../automation/azure-pipelines-nightly.yaml | 2 + build-tools/automation/azure-pipelines.yaml | 2 +- .../run-msbuild-device-tests.yaml | 2 +- .../yaml-templates/run-systemapp-tests.yaml | 52 +++++++++++++++++++ build-tools/scripts/TestApks.targets | 1 + .../Properties/Resources.resx | 6 ++- .../Properties/xlf/Resources.cs.xlf | 8 +-- .../Properties/xlf/Resources.de.xlf | 8 +-- .../Properties/xlf/Resources.es.xlf | 8 +-- .../Properties/xlf/Resources.fr.xlf | 8 +-- .../Properties/xlf/Resources.it.xlf | 8 +-- .../Properties/xlf/Resources.ja.xlf | 8 +-- .../Properties/xlf/Resources.ko.xlf | 8 +-- .../Properties/xlf/Resources.pl.xlf | 8 +-- .../Properties/xlf/Resources.pt-BR.xlf | 8 +-- .../Properties/xlf/Resources.ru.xlf | 8 +-- .../Properties/xlf/Resources.tr.xlf | 8 +-- .../Properties/xlf/Resources.zh-Hans.xlf | 8 +-- .../Properties/xlf/Resources.zh-Hant.xlf | 8 +-- .../Tasks/AndroidApkSigner.cs | 51 ++++++++++++------ .../Tasks/AndroidSignPackage.cs | 16 +++--- .../Utilities/DeviceTest.cs | 1 + .../Utilities/ResourceData.cs | 11 ++++ .../Xamarin.Android.Common.targets | 2 + .../Tests/InstallTests.cs | 15 +----- .../Tests/SystemApplicationTests.cs | 47 +++++++++++++++++ 31 files changed, 262 insertions(+), 89 deletions(-) create mode 100644 Documentation/release-notes/5708.md create mode 100644 build-tools/automation/yaml-templates/run-systemapp-tests.yaml create mode 100644 tests/MSBuildDeviceIntegration/Tests/SystemApplicationTests.cs diff --git a/.external b/.external index f66a23cd66b..d80b73c6479 100644 --- a/.external +++ b/.external @@ -1,2 +1,2 @@ -xamarin/monodroid:main@75cf1a237380e95f684438b782e3829efc5109c6 +xamarin/monodroid:main@83de4b43c1de819f21c923bc3d6aeb37cc3949cd mono/mono:2020-02@be9218f4d1f7529fbe85d15c58f6fe78161909b3 diff --git a/Documentation/guides/building-apps/build-properties.md b/Documentation/guides/building-apps/build-properties.md index 28598a14ff0..a7c0db5d867 100644 --- a/Documentation/guides/building-apps/build-properties.md +++ b/Documentation/guides/building-apps/build-properties.md @@ -1041,6 +1041,16 @@ To use a file located at `C:\Users\user1\AndroidSigningPassword.txt`: > The `env:` prefix is not supported when [`$(AndroidPackageFormat)`](#androidpackageformat) > is set to `aab`. +## AndroidSigningPlatformKey + +Specifies the key file to use to sign the apk. +This is only used when building `system` applications. + +## AndroidSigningPlatformCert + +Specifies the certificate file to use to sign the apk. +This is only used when building `system` applications. + ## AndroidSupportedAbis A string property that contains a diff --git a/Documentation/guides/messages/xa4310.md b/Documentation/guides/messages/xa4310.md index 4ff5e383ae5..f6a0241ea03 100644 --- a/Documentation/guides/messages/xa4310.md +++ b/Documentation/guides/messages/xa4310.md @@ -8,17 +8,14 @@ ms.date: 03/09/2020 ## Example messages ``` -error XA4310: `$(AndroidSigningKeyStore)` file `filename.keystore` could not be found. +error XA4310: `$(Property)` file `filename.keystore` could not be found. ``` ## Issue -The specified `$(AndroidSigningKeyStore)` file could not be located on disk. +The specified `$(Property)` file could not be located on disk. ## Solution -Check that the `$(AndroidSigningKeyStore)` MSBuild property is set to a valid -path of an existing keystore. - -This property corresponds to the **Keystore** field in the **Android Package -Signing** section of the Visual Studio project property pages. +Check that the `$(Property)` MSBuild property is set to a valid +path of an existing file. diff --git a/Documentation/release-notes/5708.md b/Documentation/release-notes/5708.md new file mode 100644 index 00000000000..47642fc1277 --- /dev/null +++ b/Documentation/release-notes/5708.md @@ -0,0 +1,13 @@ +#### Application build and deployment + +* [Developer Community 1288717][0]: + *Support Fast Deployment for System Applications.* + Added support for fast deployment while building system based + applications. Applications developed in this mode need to be + signed with a platform key and have a special attribute + + `android:sharedUserId="android.uid.system"` + + in the `AndroidManifest.xml`. + +[0]: https://developercommunity.visualstudio.com/t/VS-2019-1690-Error-XA0130-XamarinAndr/1359238 \ No newline at end of file diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/StartAndroidEmulator.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/StartAndroidEmulator.cs index a26253da525..e461f9ab103 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/StartAndroidEmulator.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/StartAndroidEmulator.cs @@ -20,6 +20,7 @@ public class StartAndroidEmulator : Task public string AndroidSdkHome {get; set;} public string Port {get; set;} public string ImageName {get; set;} = "XamarinAndroidTestRunner64"; + public string Arguments {get; set;} public string ToolPath {get; set;} public string ToolExe {get; set;} @@ -62,7 +63,7 @@ void Run (string emulator) return; var port = string.IsNullOrEmpty (Port) ? "" : $" -port {Port}"; - var arguments = $"-verbose -no-boot-anim -no-audio -no-snapshot -cache-size 512 -timezone \"Etc/UTC\" -avd {ImageName}{port}"; + var arguments = $"{Arguments ?? string.Empty} -verbose -no-boot-anim -no-audio -no-snapshot -cache-size 512 -timezone \"Etc/UTC\" -avd {ImageName}{port}"; Log.LogMessage (MessageImportance.Low, $"Tool {emulator} execution started with arguments: {arguments}"); var psi = new ProcessStartInfo () { FileName = emulator, diff --git a/build-tools/automation/azure-pipelines-nightly.yaml b/build-tools/automation/azure-pipelines-nightly.yaml index 72b517aee71..be0de81dfff 100644 --- a/build-tools/automation/azure-pipelines-nightly.yaml +++ b/build-tools/automation/azure-pipelines-nightly.yaml @@ -173,3 +173,5 @@ stages: - template: yaml-templates/run-timezoneinfo-tests.yaml parameters: node_id: 4 + + - template: yaml-templates/run-systemapp-tests.yaml diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 081a51d16c9..15bd29c06bd 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -63,7 +63,7 @@ variables: # - This is a non-fork branch with name containing "mono-" (for Mono bumps) IsMonoBranch: $[and(ne(variables['System.PullRequest.IsFork'], 'True'), or(contains(variables['Build.SourceBranchName'], 'mono-'), contains(variables['System.PullRequest.SourceBranch'], 'mono-')))] RunAllTests: $[or(eq(variables['XA.RunAllTests'], true), eq(variables['IsMonoBranch'], true))] - DotNetNUnitCategories: '& TestCategory != DotNetIgnore & TestCategory != AOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger' + DotNetNUnitCategories: '& TestCategory != DotNetIgnore & TestCategory != AOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger & TestCategory != SystemApplication' NUnit.NumberOfTestWorkers: 4 GitHub.Token: $(github--pat--vs-mobiletools-engineering-service2) CONVERT_JAVADOC_TO_XMLDOC: $[ne(variables['Build.DefinitionName'], 'Xamarin.Android-PR')] diff --git a/build-tools/automation/yaml-templates/run-msbuild-device-tests.yaml b/build-tools/automation/yaml-templates/run-msbuild-device-tests.yaml index f7aec326059..ff4fc646fcd 100644 --- a/build-tools/automation/yaml-templates/run-msbuild-device-tests.yaml +++ b/build-tools/automation/yaml-templates/run-msbuild-device-tests.yaml @@ -60,7 +60,7 @@ jobs: useDotNet: $(UseDotNet) testRunTitle: MSBuildDeviceIntegration On Device - macOS - ${{ parameters.job_suffix }} testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/MSBuildDeviceIntegration/${{ parameters.target_framework }}/MSBuildDeviceIntegration.dll - nunitConsoleExtraArgs: --where "cat != TimeZoneInfo && cat != SmokeTests ${{ parameters.nunit_categories }}" + nunitConsoleExtraArgs: --where "cat != SystemApplication && cat != TimeZoneInfo && cat != SmokeTests ${{ parameters.nunit_categories }}" dotNetTestExtraArgs: --filter "TestCategory != TimeZoneInfo & TestCategory != SmokeTests ${{ parameters.nunit_categories }}" testResultsFile: TestResult-MSBuildDeviceIntegration-${{ parameters.job_name }}-$(XA.Build.Configuration).xml diff --git a/build-tools/automation/yaml-templates/run-systemapp-tests.yaml b/build-tools/automation/yaml-templates/run-systemapp-tests.yaml new file mode 100644 index 00000000000..89d43bcae7c --- /dev/null +++ b/build-tools/automation/yaml-templates/run-systemapp-tests.yaml @@ -0,0 +1,52 @@ +# Runs TimeZoneInfo tests against an emulator running on macOS + +jobs: + - job: mac_systemapp_tests + displayName: System App Emulator Tests + pool: + vmImage: $(HostedMacImage) + timeoutInMinutes: 120 + cancelTimeoutInMinutes: 5 + workspace: + clean: all + steps: + - template: setup-test-environment.yaml + + - script: mono $(System.DefaultWorkingDirectory)/build-tools/xaprepare/xaprepare/bin/$(XA.Build.Configuration)/xaprepare.exe --s=EmulatorTestDependencies --no-emoji --run-mode=CI + displayName: install emulator + + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: $(TestAssembliesArtifactName) + downloadPath: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration) + + - task: MSBuild@1 + displayName: start emulator + inputs: + solution: tests/Mono.Android-Tests/Mono.Android-Tests.csproj + configuration: $(XA.Build.Configuration) + msbuildArguments: >- + /t:AcquireAndroidTarget /p:TestEmulatorArguments=-writable-system /bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/start-emulator.binlog + + - template: run-nunit-tests.yaml + parameters: + testRunTitle: System App On Device - macOS + testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/MSBuildDeviceIntegration/net472/MSBuildDeviceIntegration.dll + nunitConsoleExtraArgs: --where "cat == SystemApplication" + testResultsFile: TestResult-SystemApp--$(XA.Build.Configuration).xml + + - task: MSBuild@1 + displayName: shut down emulator + inputs: + solution: tests/Mono.Android-Tests/Mono.Android-Tests.csproj + configuration: $(XA.Build.Configuration) + msbuildArguments: >- + /t:AcquireAndroidTarget,ReleaseAndroidTarget + /bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog + condition: always() + + - template: upload-results.yaml + parameters: + artifactName: Test Results - System App With Emulator - macOS + + - template: fail-on-issue.yaml \ No newline at end of file diff --git a/build-tools/scripts/TestApks.targets b/build-tools/scripts/TestApks.targets index 829bfe1f456..7fa04b743c2 100644 --- a/build-tools/scripts/TestApks.targets +++ b/build-tools/scripts/TestApks.targets @@ -65,6 +65,7 @@ The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf index 89758e91cd3..6512e839176 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Soubor $(AndroidSigningKeyStore) {0} se nepovedlo najít. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + Soubor {0} {1} se nepovedlo najít. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf index e8842a503a9..78e6228bb7c 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Die $(AndroidSigningKeyStore)-Datei "{0}" wurde nicht gefunden. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + Die {0}-Datei "{1}" wurde nicht gefunden. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf index 7891fde05f0..0e9017dc780 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - No se ha encontrado el archivo "{0}" de "$(AndroidSigningKeyStore)". - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + No se ha encontrado el archivo "{1}" de "{0}". + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf index 0db56b97c2e..11e112254a6 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Le fichier '$(AndroidSigningKeyStore)' '{0}' est introuvable. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + Le fichier '{0}' '{1}' est introuvable. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf index bb577873790..b39ce8c3630 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Non è stato possibile trovare il file `{0}` di `$(AndroidSigningKeyStore)`. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + Non è stato possibile trovare il file `{1}` di `{0}`. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf index 1c298b192c0..7b2298e074c 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - '$(AndroidSigningKeyStore)' ファイル '{0}' が見つかりませんでした。 - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + '{0}' ファイル '{1}' が見つかりませんでした。 + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf index 1217ee0f137..e577d85f884 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - '$(AndroidSigningKeyStore)' 파일 '{0}'을(를) 찾을 수 없습니다. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + '{0}' 파일 '{1}'을(를) 찾을 수 없습니다. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf index f1458e19045..8fde2624c38 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Nie można odnaleźć pliku „$(AndroidSigningKeyStore)” („{0}”). - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pt-BR.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pt-BR.xlf index 78508db3557..556cbdc4a7a 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pt-BR.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pt-BR.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Não foi possível localizar o arquivo `{0}` de `$(AndroidSigningKeyStore)`. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf index 03d949606de..de02a2e6a50 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - Не удалось найти файл "$(AndroidSigningKeyStore)" с именем "{0}". - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf index e6c7afb59b1..57016ac3567 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - `{0}` adlı `$(AndroidSigningKeyStore)` dosyası bulunamadı. - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hans.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hans.xlf index f95f935c730..6ed753343bb 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hans.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hans.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - 找不到“$(AndroidSigningKeyStore)”文件“{0}”。 - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hant.xlf b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hant.xlf index a41cf9bd506..74d7effeda8 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hant.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.zh-Hant.xlf @@ -744,9 +744,11 @@ In this message, "root element" refers to the root element of an XML file. The following are literal names and should not be translated: MultiDexMainDexList - `$(AndroidSigningKeyStore)` file `{0}` could not be found. - 找不到 `$(AndroidSigningKeyStore)` 檔案 `{0}`。 - The following are literal names and should not be translated: `$(AndroidSigningKeyStore)` + `{0}` file `{1}` could not be found. + `{0}` file `{1}` could not be found. + {0} - The MSBuildProperty which contains the file name value. +{1} - The value of the MSBuildProperty. Normally a filename. + 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. diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs index dcc47e96054..83e990a030c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs @@ -20,34 +20,34 @@ public class AndroidApkSigner : JavaToolTask [Required] public ITaskItem ManifestFile { get; set; } - [Required] public string KeyStore { get; set; } - [Required] public string KeyAlias { get; set; } + public string PlatformKey { get; set; } + + public string PlatformCert { get; set; } + /// /// The Password for the Key. /// You can use the raw password here, however if you want to hide your password in logs - /// you can use a preview of env: or file: to point it to an Environment variable or + /// you can use a preview of env: or file: to point it to an Environment variable or /// a file. /// /// env: - /// file: + /// file: /// - [Required] public string KeyPass { get; set; } /// /// The Password for the Keystore. /// You can use the raw password here, however if you want to hide your password in logs - /// you can use a preview of env: or file: to point it to an Environment variable or + /// you can use a preview of env: or file: to point it to an Environment variable or /// a file. /// /// env: - /// file: + /// file: /// - [Required] public string StorePass { get; set; } public string AdditionalArguments { get; set; } @@ -81,13 +81,21 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitchIfNotNull ("-jar ", ApkSignerJar); cmd.AppendSwitch ("sign"); - cmd.AppendSwitchIfNotNull ("--ks ", KeyStore); - AddStorePass (cmd, "--ks-pass", StorePass); - cmd.AppendSwitchIfNotNull ("--ks-key-alias ", KeyAlias); - AddStorePass (cmd, "--key-pass", KeyPass); + + if (!string.IsNullOrEmpty (PlatformKey) && !string.IsNullOrEmpty (PlatformCert)) { + cmd.AppendSwitchIfNotNull ("--key ", PlatformKey); + cmd.AppendSwitchIfNotNull ("--cert ", PlatformCert); + } else { + cmd.AppendSwitchIfNotNull ("--ks ", KeyStore); + AddStorePass (cmd, "--ks-pass", StorePass); + cmd.AppendSwitchIfNotNull ("--ks-key-alias ", KeyAlias); + AddStorePass (cmd, "--key-pass", KeyPass); + } + cmd.AppendSwitchIfNotNull ("--min-sdk-version ", minSdk.ToString ()); cmd.AppendSwitchIfNotNull ("--max-sdk-version ", maxSdk.ToString ()); - + + if (!string.IsNullOrEmpty (AdditionalArguments)) cmd.AppendSwitch (AdditionalArguments); @@ -116,9 +124,20 @@ protected override string ToolName { protected override bool ValidateParameters () { - if (!string.IsNullOrEmpty (KeyStore) && !File.Exists (KeyStore)) { - Log.LogCodedError ("XA4310", Properties.Resources.XA4310, KeyStore); - return false; + if (!string.IsNullOrEmpty (PlatformKey) && !string.IsNullOrEmpty (PlatformCert)) { + if (!File.Exists (PlatformKey)) { + Log.LogCodedError ("XA4310", Properties.Resources.XA4310, "$(AndroidSigningPlatformKey)", PlatformKey); + return false; + } + if (!File.Exists (PlatformCert)) { + Log.LogCodedError ("XA4310", Properties.Resources.XA4310, "$(AndroidSigningPlatformCert)", PlatformCert); + return false; + } + } else { + if (!string.IsNullOrEmpty (KeyStore) && !File.Exists (KeyStore)) { + Log.LogCodedError ("XA4310", Properties.Resources.XA4310, "$(AndroidSigningKeyStore)", KeyStore); + return false; + } } return base.ValidateParameters (); } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs index d3cfff2ed48..efec8ba4c48 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidSignPackage.cs @@ -21,30 +21,30 @@ public class AndroidSignPackage : AndroidRunToolTask [Required] [Output] public string KeyStore { get; set; } - + [Required] public string KeyAlias { get; set; } - + /// /// The Password for the Key. /// You can use the raw password here, however if you want to hide your password in logs - /// you can use a preview of env: or file: to point it to an Environment variable or + /// you can use a preview of env: or file: to point it to an Environment variable or /// a file. /// /// env: - /// file: + /// file: /// [Required] public string KeyPass { get; set; } - + /// /// The Password for the Keystore. /// You can use the raw password here, however if you want to hide your password in logs - /// you can use a preview of env: or file: to point it to an Environment variable or + /// you can use a preview of env: or file: to point it to an Environment variable or /// a file. /// /// env: - /// file: + /// file: /// [Required] public string StorePass { get; set; } @@ -151,7 +151,7 @@ protected override string ToolName protected override bool ValidateParameters () { if (!string.IsNullOrEmpty (KeyStore) && !File.Exists (KeyStore)) { - Log.LogCodedError ("XA4310", Properties.Resources.XA4310, KeyStore); + Log.LogCodedError ("XA4310", Properties.Resources.XA4310, "$(AndroidSigningKeyStore)", KeyStore); return false; } return base.ValidateParameters (); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs index 7552268bfce..e81f56704ec 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.XPath; +using Xamarin.ProjectTools; namespace Xamarin.Android.Build.Tests { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs index 30faf133fbc..4ae42dc3280 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Xamarin.ProjectTools; namespace Xamarin.Android.Build.Tests { @@ -28,5 +29,15 @@ static byte[] GetResourceData (string name) s.CopyTo (m); return m.ToArray (); } + + public static byte [] GetKeystore (string keyname = "test.keystore") + { + var assembly = typeof (XamarinAndroidCommonProject).Assembly; + using (var stream = assembly.GetManifestResourceStream ($"Xamarin.ProjectTools.Resources.Base.{keyname}")) { + var data = new byte [stream.Length]; + stream.Read (data, 0, (int) stream.Length); + return data; + } + } } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 89451980d8d..ffcf1193357 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2304,6 +2304,8 @@ because xbuild doesn't support framework reference assemblies. KeyAlias="$(_ApkKeyAlias)" KeyPass="$(_ApkKeyPass)" StorePass="$(_ApkStorePass)" + PlatformKey="$(AndroidSigningPlatformKey)" + PlatformCert="$(AndroidSigningPlatformCert)" ToolPath="$(JavaToolPath)" ToolExe="$(JavaToolExe)" ManifestFile="$(IntermediateOutputPath)android\AndroidManifest.xml" diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs index fbee679b85d..3db4d6a5333 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallTests.cs @@ -15,16 +15,6 @@ namespace Xamarin.Android.Build.Tests [Category ("Commercial"), Category ("UsesDevice")] public class InstallTests : DeviceTest { - static byte [] GetKeystore () - { - var assembly = typeof (XamarinAndroidCommonProject).Assembly; - using (var stream = assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.test.keystore")) { - var data = new byte [stream.Length]; - stream.Read (data, 0, (int) stream.Length); - return data; - } - } - string GetContentFromAllOverrideDirectories (string packageName, bool useRunAsCommand = true) { var adbShellArgs = $"shell run-as {packageName} ls"; @@ -114,7 +104,7 @@ public void ChangeKeystoreRedeploy () using (var builder = CreateApkBuilder ()) { // Use the default debug.keystore XA generates Assert.IsTrue (builder.Install (proj), "first install should succeed."); - byte [] data = GetKeystore (); + byte [] data = ResourceData.GetKeystore (); proj.OtherBuildItems.Add (new BuildItem (BuildActions.None, "test.keystore") { BinaryContent = () => data }); @@ -387,7 +377,7 @@ public void TestAndroidStoreKey (bool useApkSigner, bool isRelease, string packa string path = Path.Combine ("temp", TestName.Replace (expected, expected.Replace ("-", "_"))); string storepassfile = Path.Combine (Root, path, "storepass.txt"); string keypassfile = Path.Combine (Root, path, "keypass.txt"); - byte [] data = GetKeystore (); + byte [] data = ResourceData.GetKeystore (); var proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease, }; @@ -587,6 +577,5 @@ public void IncrementalFastDeployment () $"Fourth unchanged install: '{fourthInstalTime}' should be faster than clean install: '{firstInstallTime}' and incremental install: '{thirdInstallTime}'."); } } - } } diff --git a/tests/MSBuildDeviceIntegration/Tests/SystemApplicationTests.cs b/tests/MSBuildDeviceIntegration/Tests/SystemApplicationTests.cs new file mode 100644 index 00000000000..117e84d51a5 --- /dev/null +++ b/tests/MSBuildDeviceIntegration/Tests/SystemApplicationTests.cs @@ -0,0 +1,47 @@ +using System; +using NUnit.Framework; +using Xamarin.ProjectTools; +using System.IO; +using System.Linq; +using Microsoft.Build.Framework; +using System.Text; +using System.Xml.Linq; +using System.Collections.Generic; + +namespace Xamarin.Android.Build.Tests +{ + [TestFixture] + [NonParallelizable] //These tests deploy to devices + [Category ("Commercial"), Category ("UsesDevice")] + public class SystemApplicationTests : DeviceTest + { + // All Tests here require the emulator to be started with -writable-system + [Test, Category ("SystemApplication")] + public void SystemApplicationCanInstall () + { + AssertCommercialBuild (); + AssertHasDevices (); + + var proj = new XamarinAndroidApplicationProject () { + IsRelease = false, + EmbedAssembliesIntoApk = false, + }; + proj.OtherBuildItems.Add (new BuildItem ("None", "platform.pk8") { + WebContent = "https://github.com/aosp-mirror/platform_build/raw/master/target/product/security/platform.pk8" + }); + proj.OtherBuildItems.Add (new BuildItem ("None", "platform.x509.pem") { + WebContent = "https://github.com/aosp-mirror/platform_build/raw/master/target/product/security/platform.x509.pem" + }); + proj.AndroidManifest = proj.AndroidManifest.Replace (" Date: Tue, 23 Mar 2021 20:55:30 -0400 Subject: [PATCH 2/2] Mention when the new properties were added --- Documentation/guides/building-apps/build-properties.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/guides/building-apps/build-properties.md b/Documentation/guides/building-apps/build-properties.md index a7c0db5d867..202d96c6408 100644 --- a/Documentation/guides/building-apps/build-properties.md +++ b/Documentation/guides/building-apps/build-properties.md @@ -1046,11 +1046,15 @@ To use a file located at `C:\Users\user1\AndroidSigningPassword.txt`: Specifies the key file to use to sign the apk. This is only used when building `system` applications. +Support for this property was added in Xamarin.Android 11.3. + ## AndroidSigningPlatformCert Specifies the certificate file to use to sign the apk. This is only used when building `system` applications. +Support for this property was added in Xamarin.Android 11.3. + ## AndroidSupportedAbis A string property that contains a