diff --git a/android/buildIcons.nix b/android/buildIcons.nix index 9f6f7b856..ac19679f7 100644 --- a/android/buildIcons.nix +++ b/android/buildIcons.nix @@ -1,8 +1,17 @@ -{ runCommand, imagemagick }: -{ src }: +{ runCommand, imagemagick, lib }: +{ src ? null # Base raster image for fixed-size icons (must be a path) +, adaptiveIcon ? null + # Path to a XML file containing the adaptive icon specification (SDK + # 26 and up). +}: +let + rasterInput = + if (src == null) && (adaptiveIcon == null) + then abort "Either src or adaptiveIcon must be specified!" + else src; +in runCommand "android-icons" { - inherit src; - buildCommand = '' + buildCommand = lib.optionalString (src != null) '' mkdir "$out" launcherIconSize() { @@ -20,8 +29,11 @@ runCommand "android-icons" { for x in l m tv h xh xxh xxxh ; do local dir="$out/drawable-''${x}dpi" mkdir "$dir" - convert -resize "$(launcherIconSize "$x")" -flatten "$src" "$dir/ic_launcher.png" + convert -resize "$(launcherIconSize "$x")" -flatten "${rasterInput}" "$dir/ic_launcher.png" done + '' + lib.optionalString (adaptiveIcon != null) '' + mkidr -p "$out/mipmap-anydpi-v26/" + cp "${adaptiveIcon}" "$out/mipmap-anydpi-v26/ic_launcher.xml" ''; nativeBuildInputs = [ imagemagick