Skip to content

Commit b28a93a

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Rework AndroidApkSigner to use .jar directly. (#1222)
Once again we hit an issue where the `apksigner.bat` file provided with android build-tools was not functioning correctly. So like we did with `dx.bat` and other tooling we should switch to using the `apksigner.jar` file directly. Additionally JDK 9 has removed support for the `java.ext.dirs`, which all versions of the `apksigner.bat` use. As a result this tool will not work with JDK 9. So its best to remove it now. We have existing unit tests which check that the Apk is being signed correctly. So not additional tests are required.
1 parent 84b6f66 commit b28a93a

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/AndroidApkSigner.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
namespace Xamarin.Android.Tasks
88
{
9-
public class AndroidApkSigner : AndroidToolTask
9+
public class AndroidApkSigner : JavaToolTask
1010
{
11+
[Required]
12+
public string ApkSignerJar { get; set; }
13+
1114
[Required]
1215
public string ApkToSign { get; set; }
1316

@@ -31,6 +34,7 @@ public class AndroidApkSigner : AndroidToolTask
3134
public override bool Execute ()
3235
{
3336
Log.LogDebugMessage ("AndroidApkSigner:");
37+
Log.LogDebugMessage (" ApkSignerJar: {0}", ApkSignerJar);
3438
Log.LogDebugMessage (" ApkToSign: {0}", ApkToSign);
3539
Log.LogDebugMessage (" ManifestFile: {0}", ManifestFile);
3640
Log.LogDebugMessage (" AdditionalArguments: {0}", AdditionalArguments);
@@ -57,6 +61,8 @@ protected override string GenerateCommandLineCommands ()
5761
maxSdk = manifest.TargetSdkVersion.Value;
5862

5963
minSdk = Math.Min (minSdk, maxSdk);
64+
65+
cmd.AppendSwitchIfNotNull ("-jar ", ApkSignerJar);
6066
cmd.AppendSwitch ("sign");
6167
cmd.AppendSwitchIfNotNull ("--ks ", KeyStore);
6268
cmd.AppendSwitchIfNotNull ("--ks-pass pass:", StorePass);
@@ -68,16 +74,11 @@ protected override string GenerateCommandLineCommands ()
6874
if (!string.IsNullOrEmpty (AdditionalArguments))
6975
cmd.AppendSwitch (AdditionalArguments);
7076

71-
cmd.AppendSwitchIfNotNull (" ", ApkToSign);
77+
cmd.AppendSwitchIfNotNull (" ", Path.GetFullPath (ApkToSign));
7278

7379
return cmd.ToString ();
7480
}
7581

76-
protected override string GenerateFullPathToTool ()
77-
{
78-
return Path.Combine (ToolPath, ToolExe);
79-
}
80-
8182
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
8283
{
8384
singleLine = singleLine.Trim ();
@@ -93,9 +94,7 @@ protected override void LogEventsFromTextOutput (string singleLine, MessageImpor
9394
}
9495

9596
protected override string ToolName {
96-
get {
97-
return ToolExe;
98-
}
97+
get { return OS.IsWindows ? "java.exe" : "java"; }
9998
}
10099
}
101100
}

src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ResolveSdks : Task
111111
public string LintToolPath { get; set; }
112112

113113
[Output]
114-
public string ApkSignerToolExe { get; set; }
114+
public string ApkSignerJar { get; set; }
115115

116116
[Output]
117117
public bool AndroidUseApkSigner { get; set; }
@@ -127,7 +127,7 @@ public class ResolveSdks : Task
127127
static readonly string Aapt = IsWindows ? "aapt.exe" : "aapt";
128128
static readonly string Android = IsWindows ? "android.bat" : "android";
129129
static readonly string Lint = IsWindows ? "lint.bat" : "lint";
130-
static readonly string ApkSigner = "apksigner";
130+
static readonly string ApkSigner = "apksigner.jar";
131131

132132

133133
public override bool Execute ()
@@ -229,8 +229,8 @@ public bool RunTask ()
229229
return false;
230230
}
231231

232-
ApkSignerToolExe = MonoAndroidHelper.GetExecutablePath (AndroidSdkBuildToolsBinPath, ApkSigner);
233-
AndroidUseApkSigner = File.Exists (Path.Combine (AndroidSdkBuildToolsBinPath, ApkSignerToolExe));
232+
ApkSignerJar = Path.Combine (AndroidSdkBuildToolsBinPath, "lib", ApkSigner);
233+
AndroidUseApkSigner = File.Exists (ApkSignerJar);
234234

235235
if (string.IsNullOrEmpty (ZipAlignPath) || !Directory.Exists (ZipAlignPath)) {
236236
ZipAlignPath = new[]{

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
662662
<Output TaskParameter="AndroidSdkBuildToolsBinPath" PropertyName="AndroidSdkBuildToolsBinPath" Condition="'$(AndroidSdkBuildToolsBinPath)' == ''" />
663663
<Output TaskParameter="AndroidSequencePointsMode" PropertyName="_SequencePointsMode" Condition="'$(_SequencePointsMode)' == ''" />
664664
<Output TaskParameter="LintToolPath" PropertyName="LintToolPath" Condition="'$(LintToolPath)' == ''" />
665-
<Output TaskParameter="ApkSignerToolExe" PropertyName="ApkSignerToolExe" Condition="'$(ApkSignerToolExe)' == ''" />
665+
<Output TaskParameter="ApkSignerJar" PropertyName="ApkSignerJar" Condition="'$(ApkSignerJar)' == ''" />
666666
<Output TaskParameter="AndroidUseApkSigner" PropertyName="AndroidUseApkSigner" Condition="'$(AndroidUseApkSigner)' == ''" />
667667
<Output TaskParameter="JdkVersion" PropertyName="_JdkVersion" />
668668
<Output TaskParameter="MinimumRequiredJdkVersion" PropertyName="_DefaultJdkVersion" />
@@ -2551,13 +2551,14 @@ because xbuild doesn't support framework reference assemblies.
25512551
ToolExe="$(ZipalignToolExe)"
25522552
/>
25532553
<AndroidApkSigner Condition=" '$(AndroidUseApkSigner)' == 'true' "
2554+
ApkSignerJar="$(ApkSignerJar)"
25542555
ApkToSign="$(ApkFileSigned)"
25552556
KeyStore="$(_ApkKeyStore)"
25562557
KeyAlias="$(_ApkKeyAlias)"
25572558
KeyPass="$(_ApkKeyPass)"
25582559
StorePass="$(_ApkStorePass)"
2559-
ToolPath="$(AndroidSdkBuildToolsBinPath)"
2560-
ToolExe="$(ApkSignerToolExe)"
2560+
ToolPath="$(JavaToolPath)"
2561+
ToolExe="$(JavaToolExe)"
25612562
ManifestFile="$(IntermediateOutputPath)android\AndroidManifest.xml"
25622563
AdditionalArguments="$(AndroidApkSignerAdditionalArguments)"
25632564
/>

0 commit comments

Comments
 (0)