From 27e91bb49e5d9f5f706010a4734f40eab82d196a Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 29 Jul 2021 15:56:46 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] NullReferenceException in Xamarin.Android.Common.targets (#6126) Fixes: https://github.com/xamarin/xamarin-android/issues/6124 Commit 2a04748d removed the `[Required]` attribute from the `AndroidApkSigner.KeyPass` and `AndroidApkSigner.StorePass` properties. This was because they were now optional. However `keytool` REQUIRES these parameters when we use the `-ks` or `KeyStore` argument. If a user does not pass these arguments they get the following error error XAAAS7001: System.NullReferenceException: Object reference not set to an instance of an object. error XAAAS7001: at Xamarin.Android.Tasks.AndroidApkSigner.AddStorePass(CommandLineBuilder cmd, String cmdLineSwitch, String value) error XAAAS7001: at Xamarin.Android.Tasks.AndroidApkSigner.GenerateCommandLineCommands() This is because the `KeyPass` or `StorePass` are `null` and the `AndroidApkSigner.AddStorePass()` method did not handle that. Instead, when the `KeyStore` argument is being used we should error out if `KeyPass` or `StorePass` are empty or `null`, emitting a new `XA4314` error, e.g.: error XA4314: `$(AndroidSigningKeyPass)` is empty. A value for `$(AndroidSigningKeyPass)` should be provided. --- Documentation/guides/messages/README.md | 1 + Documentation/guides/messages/xa4314.md | 20 +++++++++++++++++++ .../Properties/Resources.resx | 5 +++++ .../Properties/xlf/Resources.cs.xlf | 6 ++++++ .../Properties/xlf/Resources.de.xlf | 6 ++++++ .../Properties/xlf/Resources.es.xlf | 6 ++++++ .../Properties/xlf/Resources.fr.xlf | 6 ++++++ .../Properties/xlf/Resources.it.xlf | 6 ++++++ .../Properties/xlf/Resources.ja.xlf | 6 ++++++ .../Properties/xlf/Resources.ko.xlf | 6 ++++++ .../Properties/xlf/Resources.pl.xlf | 6 ++++++ .../Properties/xlf/Resources.pt-BR.xlf | 6 ++++++ .../Properties/xlf/Resources.ru.xlf | 6 ++++++ .../Properties/xlf/Resources.tr.xlf | 6 ++++++ .../Properties/xlf/Resources.zh-Hans.xlf | 6 ++++++ .../Properties/xlf/Resources.zh-Hant.xlf | 6 ++++++ .../Tasks/AndroidApkSigner.cs | 12 +++++++++-- 17 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 Documentation/guides/messages/xa4314.md diff --git a/Documentation/guides/messages/README.md b/Documentation/guides/messages/README.md index 62f21bf0d14..7b1ab77bc2d 100644 --- a/Documentation/guides/messages/README.md +++ b/Documentation/guides/messages/README.md @@ -182,6 +182,7 @@ or 'Help->Report a Problem' in Visual Studio for Mac. + XA4311: 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. + [XA4312](xa4312.md): Referencing an Android Wear application project from an Android application project is deprecated. + [XA4313](xa4313.md): Framework assembly has been deprecated. ++ [XA4314](xa4314.md): `$(Property)` is empty. A value for `$(Property)` should be provided. ## XA5xxx: GCC and toolchain diff --git a/Documentation/guides/messages/xa4314.md b/Documentation/guides/messages/xa4314.md new file mode 100644 index 00000000000..f62869a644d --- /dev/null +++ b/Documentation/guides/messages/xa4314.md @@ -0,0 +1,20 @@ +--- +title: Xamarin.Android error XA4314 +description: XA4314 error code +ms.date: 26/07/2021 +--- +# Xamarin.Android warning XA4314 + +## Example messages + +``` +error XA4314: `$(Property)` is empty. A value for `$(Property)` should be provided. +``` + +## Issue + +The specified `$(Property)` does not have a value which is required. + +## Solution + +Check that the `$(Property)` MSBuild property is set to a valid value. \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 20a4fe0ce2f..2dbf81c243b 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -732,6 +732,11 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + Missing Android NDK toolchains directory '{0}'. Please install the Android NDK. 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 1f2646def1f..79faa2870d6 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 33e797d4530..e9592d27a7d 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 0bd683e4232..d9dd1dea013 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 c35f8ad543b..9767bcdf649 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 828293d14bf..388946ecc24 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 2a7d4a1477d..f5f8c61be8c 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 a32958ed82c..fb37c7824b8 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 e12893a8d97..58ea4ac401b 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 48e3095099a..971964540da 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 @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 4f6707cac06..4a484ee6c76 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ru.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 72396790318..74f239a6816 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf +++ b/src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.tr.xlf @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 e36a508ed3c..be454d9638e 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 @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + 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 21b50c3fc08..5564ddd4b1c 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 @@ -83,6 +83,12 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The Assembly name which is deprecated {1} - A Nuget package name. + + + `{0}` is empty. A value for `{0}` should be provided. + `{0}` is empty. A value for `{0}` should be provided. + {0} - The MSBuildProperty which contains a value. + diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs index 83e990a030c..8293376333f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs @@ -37,7 +37,7 @@ public class AndroidApkSigner : JavaToolTask /// env: /// file: /// - public string KeyPass { get; set; } + public string KeyPass { get; set; } = string.Empty; /// /// The Password for the Keystore. @@ -48,7 +48,7 @@ public class AndroidApkSigner : JavaToolTask /// env: /// file: /// - public string StorePass { get; set; } + public string StorePass { get; set; } = string.Empty; public string AdditionalArguments { get; set; } @@ -138,6 +138,14 @@ protected override bool ValidateParameters () Log.LogCodedError ("XA4310", Properties.Resources.XA4310, "$(AndroidSigningKeyStore)", KeyStore); return false; } + if (string.IsNullOrEmpty (KeyPass)) { + Log.LogCodedError ("XA4314", Properties.Resources.XA4314, "$(AndroidSigningKeyPass)"); + return false; + } + if (string.IsNullOrEmpty (StorePass)) { + Log.LogCodedError ("XA4314", Properties.Resources.XA4314, "$(AndroidSigningStorePass)"); + return false; + } } return base.ValidateParameters (); }