Skip to content

Commit

Permalink
Use separate images
Browse files Browse the repository at this point in the history
Commit 1d38470 worked, in that we
no longer get insta-crashes on Windows!
The `System.Runtime.CompilerServices.Unsafe` crash was fixed!

We now turn our attention to the XA0102 warnings, which are *also*
responsible for errors in `BuildReleaseArm64()`, because the `.apk`
size now differs, because the icons are now larger; `.apk` size
increased by 31,744 bytes!

…which is why SixLabors.ImageSharp was used…

Avoid SixLabors.ImageSharp and instead have
`Xamarin.ProjectTools` use the same icons as the
`dotnet new android` template, in
`src\Microsoft.Android.Templates\android\Resources\**\appicon.png`.
In order to ensure sane `%(LogicalName)` values, `%(RecrusiveDir)`
is used as part of the logical name, resulting in resource names
on macOS such as:

  * `mipmap-hdpi/appicon.png`
  * `mipmap-mdpi/appicon.png`
  * `mipmap-xhdpi/appicon.png`
  * `mipmap-xxhdpi/appicon.png`
  * `mipmap-xxxhdpi/appicon.png`

I'm not sure what Windows will do offhand, so have
Xamarin.ProjectTools.dll *also* look for a resource name with
`/` replaced by `\` (`Path.DirectorySeparatorChar`) so that this
logic *should* work on Windows as well.

Hopefully this will resolve the XA0102 warnings and the
`BuildReleaseArm64()` errors.
  • Loading branch information
jonpryor committed Nov 17, 2022
1 parent 1d38470 commit 7db57b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ public abstract class XamarinAndroidCommonProject : XamarinAndroidProject

static XamarinAndroidCommonProject ()
{
var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.Icon.png");
icon_binary_mdpi = new byte [stream.Length];
stream.Read (icon_binary_mdpi, 0, (int) stream.Length);
icon_binary_mdpi = GetResourceContents ("mipmap-mdpi/appicon.png");
icon_binary_hdpi = GetResourceContents ("mipmap-hdpi/appicon.png");
icon_binary_xhdpi = GetResourceContents ("mipmap-xhdpi/appicon.png");
icon_binary_xxhdpi = GetResourceContents ("mipmap-xxhdpi/appicon.png");
icon_binary_xxxhdpi = GetResourceContents ("mipmap-xxxhdpi/appicon.png");
}

icon_binary_hdpi = icon_binary_mdpi;
icon_binary_xhdpi = icon_binary_mdpi;
icon_binary_xxhdpi = icon_binary_mdpi;
icon_binary_xxxhdpi = icon_binary_mdpi;
static byte[] GetResourceContents (string resourceName)
{
var assembly = typeof (XamarinAndroidCommonProject).Assembly;
var stream = assembly.GetManifestResourceStream (resourceName) ??
assembly.GetManifestResourceStream (resourceName.Replace ('/', Path.DirectorySeparatorChar));
if (stream == null) {
return Array.Empty<byte>();
}
using (stream) {
var contents = new byte [stream.Length];
stream.Read (contents, 0, (int) stream.Length);
return contents;
}
}

protected XamarinAndroidCommonProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<Compile Remove="Resources\**\*.cs" />
<Compile Include="..\..\..\..\bin\Build$(Configuration)\XABuildConfig.cs" />
<EmbeddedResource Include="Resources\**\*" />
<EmbeddedResource Include="..\..\..\Microsoft.Android.Templates\android\Resources\**\appicon.png">
<LogicalName>%(RecursiveDir)appicon.png</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\..\..\.nuget\NuGet.exe">
Expand Down

0 comments on commit 7db57b1

Please sign in to comment.