Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] NullReferenceException in Xamarin.Andro…
Browse files Browse the repository at this point in the history
…id.Common.targets (#6126)

Fixes: #6124

Commit 2a04748 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.
  • Loading branch information
dellis1972 committed Jul 29, 2021
1 parent 810c917 commit 27e91bb
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 2 deletions.
1 change: 1 addition & 0 deletions Documentation/guides/messages/README.md
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions 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.
5 changes: 5 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Expand Up @@ -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.
</comment>
</data>
<data name="XA4314" xml:space="preserve">
<value>`{0}` is empty. A value for `{0}` should be provided.</value>
<comment>{0} - The MSBuildProperty which contains a value.
</comment>
</data>
<data name="XA5101" xml:space="preserve">
<value>Missing Android NDK toolchains directory '{0}'. Please install the Android NDK.</value>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Expand Up @@ -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.
</note>
</trans-unit>
<trans-unit id="XA4314">
<source>`{0}` is empty. A value for `{0}` should be provided.</source>
<target state="new">`{0}` is empty. A value for `{0}` should be provided.</target>
<note>{0} - The MSBuildProperty which contains a value.
</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
12 changes: 10 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs
Expand Up @@ -37,7 +37,7 @@ public class AndroidApkSigner : JavaToolTask
/// env:<PasswordEnvironentVariable>
/// file:<PasswordFile>
/// </summary>
public string KeyPass { get; set; }
public string KeyPass { get; set; } = string.Empty;

/// <summary>
/// The Password for the Keystore.
Expand All @@ -48,7 +48,7 @@ public class AndroidApkSigner : JavaToolTask
/// env:<PasswordEnvironentVariable>
/// file:<PasswordFile>
/// </summary>
public string StorePass { get; set; }
public string StorePass { get; set; } = string.Empty;

public string AdditionalArguments { get; set; }

Expand Down Expand Up @@ -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 ();
}
Expand Down

0 comments on commit 27e91bb

Please sign in to comment.