1
- #nullable disable
1
+ #nullable enable
2
2
3
3
using System ;
4
4
using System . IO ;
@@ -14,21 +14,21 @@ public class AndroidApkSigner : JavaToolTask
14
14
public override string TaskPrefix => "AAS" ;
15
15
16
16
[ Required ]
17
- public string ApkSignerJar { get ; set ; }
17
+ public string ApkSignerJar { get ; set ; } = "" ;
18
18
19
19
[ Required ]
20
- public string ApkToSign { get ; set ; }
20
+ public string ApkToSign { get ; set ; } = "" ;
21
21
22
22
[ Required ]
23
- public ITaskItem ManifestFile { get ; set ; }
23
+ public ITaskItem ManifestFile { get ; set ; } = null ! ;
24
24
25
- public string KeyStore { get ; set ; }
25
+ public string ? KeyStore { get ; set ; }
26
26
27
- public string KeyAlias { get ; set ; }
27
+ public string ? KeyAlias { get ; set ; }
28
28
29
- public string PlatformKey { get ; set ; }
29
+ public string ? PlatformKey { get ; set ; }
30
30
31
- public string PlatformCert { get ; set ; }
31
+ public string ? PlatformCert { get ; set ; }
32
32
33
33
/// <summary>
34
34
/// The Password for the Key.
@@ -39,7 +39,7 @@ public class AndroidApkSigner : JavaToolTask
39
39
/// env:<PasswordEnvironentVariable>
40
40
/// file:<PasswordFile>
41
41
/// </summary>
42
- public string KeyPass { get ; set ; } = string . Empty ;
42
+ public string KeyPass { get ; set ; } = "" ;
43
43
44
44
/// <summary>
45
45
/// The Password for the Keystore.
@@ -50,15 +50,15 @@ public class AndroidApkSigner : JavaToolTask
50
50
/// env:<PasswordEnvironentVariable>
51
51
/// file:<PasswordFile>
52
52
/// </summary>
53
- public string StorePass { get ; set ; } = string . Empty ;
53
+ public string StorePass { get ; set ; } = "" ;
54
54
55
- public string AdditionalArguments { get ; set ; }
55
+ public string ? AdditionalArguments { get ; set ; }
56
56
57
57
void AddStorePass ( CommandLineBuilder cmd , string cmdLineSwitch , string value )
58
58
{
59
- string pass = value . Replace ( "env:" , string . Empty )
60
- . Replace ( "file:" , string . Empty )
61
- . Replace ( "pass:" , string . Empty ) ;
59
+ string pass = value . Replace ( "env:" , "" )
60
+ . Replace ( "file:" , "" )
61
+ . Replace ( "pass:" , "" ) ;
62
62
if ( value . StartsWith ( "env:" , StringComparison . Ordinal ) ) {
63
63
cmd . AppendSwitchIfNotNull ( $ "{ cmdLineSwitch } env:", pass ) ;
64
64
}
@@ -74,20 +74,21 @@ protected override string GenerateCommandLineCommands ()
74
74
var cmd = new CommandLineBuilder ( ) ;
75
75
76
76
var manifest = AndroidAppManifest . Load ( ManifestFile . ItemSpec , MonoAndroidHelper . SupportedVersions ) ;
77
- int minSdk = MonoAndroidHelper . SupportedVersions . MinStableVersion . ApiLevel ;
78
- int maxSdk = MonoAndroidHelper . SupportedVersions . MaxStableVersion . ApiLevel ;
77
+ int ? minSdk = MonoAndroidHelper . SupportedVersions . MinStableVersion ? . ApiLevel ;
78
+ int ? maxSdk = MonoAndroidHelper . SupportedVersions . MaxStableVersion ? . ApiLevel ;
79
79
if ( manifest . MinSdkVersion . HasValue )
80
80
minSdk = manifest . MinSdkVersion . Value ;
81
81
82
82
if ( manifest . TargetSdkVersion . HasValue )
83
83
maxSdk = manifest . TargetSdkVersion . Value ;
84
84
85
- minSdk = Math . Min ( minSdk , maxSdk ) ;
85
+ if ( minSdk . HasValue && maxSdk . HasValue )
86
+ minSdk = Math . Min ( minSdk . Value , maxSdk . Value ) ;
86
87
87
88
cmd . AppendSwitchIfNotNull ( "-jar " , ApkSignerJar ) ;
88
89
cmd . AppendSwitch ( "sign" ) ;
89
90
90
- if ( ! string . IsNullOrEmpty ( PlatformKey ) && ! string . IsNullOrEmpty ( PlatformCert ) ) {
91
+ if ( ! PlatformKey . IsNullOrEmpty ( ) && ! PlatformCert . IsNullOrEmpty ( ) ) {
91
92
cmd . AppendSwitchIfNotNull ( "--key " , PlatformKey ) ;
92
93
cmd . AppendSwitchIfNotNull ( "--cert " , PlatformCert ) ;
93
94
} else {
@@ -97,11 +98,15 @@ protected override string GenerateCommandLineCommands ()
97
98
AddStorePass ( cmd , "--key-pass" , KeyPass ) ;
98
99
}
99
100
100
- cmd . AppendSwitchIfNotNull ( "--min-sdk-version " , minSdk . ToString ( ) ) ;
101
- cmd . AppendSwitchIfNotNull ( "--max-sdk-version " , maxSdk . ToString ( ) ) ;
101
+ if ( minSdk is not null ) {
102
+ cmd . AppendSwitchIfNotNull ( "--min-sdk-version " , minSdk . ToString ( ) ) ;
103
+ }
104
+ if ( maxSdk is not null ) {
105
+ cmd . AppendSwitchIfNotNull ( "--max-sdk-version " , maxSdk . ToString ( ) ) ;
106
+ }
102
107
103
108
104
- if ( ! string . IsNullOrEmpty ( AdditionalArguments ) )
109
+ if ( ! AdditionalArguments . IsNullOrEmpty ( ) )
105
110
cmd . AppendSwitch ( AdditionalArguments ) ;
106
111
107
112
cmd . AppendSwitchIfNotNull ( " " , ApkToSign ) ;
@@ -129,7 +134,7 @@ protected override string ToolName {
129
134
130
135
protected override bool ValidateParameters ( )
131
136
{
132
- if ( ! string . IsNullOrEmpty ( PlatformKey ) && ! string . IsNullOrEmpty ( PlatformCert ) ) {
137
+ if ( ! PlatformKey . IsNullOrEmpty ( ) && ! PlatformCert . IsNullOrEmpty ( ) ) {
133
138
if ( ! File . Exists ( PlatformKey ) ) {
134
139
Log . LogCodedError ( "XA4310" , Properties . Resources . XA4310 , "$(AndroidSigningPlatformKey)" , PlatformKey ) ;
135
140
return false ;
@@ -139,15 +144,15 @@ protected override bool ValidateParameters ()
139
144
return false ;
140
145
}
141
146
} else {
142
- if ( ! string . IsNullOrEmpty ( KeyStore ) && ! File . Exists ( KeyStore ) ) {
147
+ if ( ! KeyStore . IsNullOrEmpty ( ) && ! File . Exists ( KeyStore ) ) {
143
148
Log . LogCodedError ( "XA4310" , Properties . Resources . XA4310 , "$(AndroidSigningKeyStore)" , KeyStore ) ;
144
149
return false ;
145
150
}
146
- if ( string . IsNullOrEmpty ( KeyPass ) ) {
151
+ if ( KeyPass . IsNullOrEmpty ( ) ) {
147
152
Log . LogCodedError ( "XA4314" , Properties . Resources . XA4314 , "$(AndroidSigningKeyPass)" ) ;
148
153
return false ;
149
154
}
150
- if ( string . IsNullOrEmpty ( StorePass ) ) {
155
+ if ( StorePass . IsNullOrEmpty ( ) ) {
151
156
Log . LogCodedError ( "XA4314" , Properties . Resources . XA4314 , "$(AndroidSigningStorePass)" ) ;
152
157
return false ;
153
158
}
0 commit comments