Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Always create the debug.keystore (dotne…
Browse files Browse the repository at this point in the history
…t#1148)

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=61065

If a user sets the `$(AndroidKeyStore)` to `True` for a
debug configuration they will get the following error.

	[MESSAGE] jarsigner error: java.lang.RuntimeException: keystore load: /Users/$(user)/.local/share/Xamarin/Mono for Android/debug.keystore (No such file or directory)

Note this will only happen if they have NEVER build with
`$(AndroidKeyStore)` set to `False`. This is because we
don't always generate the `debug.keystore`.

So rather than hitting this issue we should always generate the
`debug.keystore` regardless of what the setting for `$(AndroidKeyStore)`
is. This commit splits out the keystore generation into its own
target. This target will check the existance of the file and
generate it if required. We also move all the debug key property
values into Properties so that they can be updated in one place.
  • Loading branch information
dellis1972 authored and jonpryor committed Jan 4, 2018
1 parent d7f96cd commit 5b2e027
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public void BuildBasicApplicationReleaseFSharp ()
}
}

[Test]
public void CheckKeystoreIsCreated ()
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
};
using (var b = CreateApkBuilder ("temp/CheckKeystoreIsCreated", false, false)) {
var file = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "debug.keystore");
var p = new string [] {
$"_ApkDebugKeyStore={file}",
};
Assert.IsTrue (b.Build (proj, parameters: p), "Build should have succeeded.");
FileAssert.Exists (file, $"{file} should have been created.");
}
}

[Test]
public void FSharpAppHasAndroidDefine ()
{
Expand Down
32 changes: 19 additions & 13 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ because xbuild doesn't support framework reference assemblies.
</CreateProperty>

<CreateProperty Value="$(_AppSettingsDirectory)debug.keystore">
<Output TaskParameter="Value" PropertyName="_ApkDebugKeyStore"/>
<Output TaskParameter="Value" PropertyName="_ApkDebugKeyStore"
Condition="'$(_ApkDebugKeyStore)' == ''"
/>
</CreateProperty>

<CreateProperty Value="$(MonoAndroidToolsDirectory)">
Expand Down Expand Up @@ -2455,9 +2457,23 @@ because xbuild doesn't support framework reference assemblies.

<Delete Files="$(_UploadFlagFile)" Condition="Exists ('$(_UploadFlagFile)')" />
</Target>


<Target Name="_ResolveAndroidSigningKey" DependsOnTargets="$(_OnResolveMonoAndroidSdks)">
<Target Name="_CreateAndroidDebugSigningKey"
Condition="!Exists ('$(_ApkDebugKeyStore)')"
DependsOnTargets="$(_OnResolveMonoAndroidSdks)"
>
<AndroidCreateDebugKey
KeyStore="$(_ApkDebugKeyStore)"
KeyAlias="androiddebugkey"
KeyPass="android"
StorePass="android"
ToolPath="$(KeytoolToolPath)"
ToolExe="$(KeytoolToolExe)"
Command="-genkeypair"
/>
</Target>

<Target Name="_ResolveAndroidSigningKey" DependsOnTargets="$(_OnResolveMonoAndroidSdks);_CreateAndroidDebugSigningKey">
<!-- would use a PropertyGroup here but xbuild doesn't support it -->
<CreateProperty Value="$(_ApkDebugKeyStore)" Condition="'$(AndroidKeyStore)'!='True'">
<Output TaskParameter="Value" PropertyName="_ApkKeyStore"/>
Expand All @@ -2484,16 +2500,6 @@ because xbuild doesn't support framework reference assemblies.
<CreateProperty Value="$(AndroidSigningKeyPass)" Condition="'$(AndroidKeyStore)'=='True'">
<Output TaskParameter="Value" PropertyName="_ApkKeyPass"/>
</CreateProperty>

<AndroidCreateDebugKey
KeyStore="$(_ApkKeyStore)"
KeyAlias="$(_ApkKeyAlias)"
KeyPass="$(_ApkKeyPass)"
StorePass="$(_ApkStorePass)"
ToolPath="$(KeytoolToolPath)"
ToolExe="$(KeytoolToolExe)"
Command="-genkeypair"
Condition="'$(AndroidKeyStore)'=='' and !Exists ('$(_ApkKeyStore)')" />

<Delete Files="$(_AndroidDebugKeyStoreFlag)" Condition="'$(AndroidKeyStore)'=='True'" />
<Touch Files="$(_AndroidDebugKeyStoreFlag)" AlwaysCreate="True" Condition="'$(AndroidKeyStore)'!='True'" />
Expand Down

0 comments on commit 5b2e027

Please sign in to comment.