From ebaabcf2d4cee37e05c24358ce7771c6e8da98fa Mon Sep 17 00:00:00 2001 From: Jumpei Matsuda Date: Mon, 16 Dec 2019 17:25:59 +0900 Subject: [PATCH 1/2] Support weird adaptive icon apks --- lib/android_apk.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/android_apk.rb b/lib/android_apk.rb index 0185565..022f84f 100644 --- a/lib/android_apk.rb +++ b/lib/android_apk.rb @@ -158,19 +158,26 @@ def icon_file(dpi = nil, want_png = false) icon = dpi ? self.icons[dpi.to_i] : self.icon return nil if icon.nil? || icon.empty? + # Unfroze just in case + icon = +icon + dpis = dpi_str(dpi) + + # neat adaptive icon apk + if want_png && icon.end_with?(".xml") + icon.gsub!(%r{res/(drawable|mipmap)-anydpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png") + end + + # 1st fallback is for WEIRD adaptive icon apk e.g. Cordiva generates such apks if want_png && icon.end_with?(".xml") - dpis = dpi_str(dpi) - icon.gsub! %r{res/(drawable|mipmap)-anydpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png" + icon.gsub!(%r{res/(drawable|mipmap)-.+?dpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png") end - # a fallback to a png file which is manually resolved + # 2nd fallback is for vector drawable icon apk. Use a png file which is manually resolved if want_png && icon.end_with?(".xml") - dpis = dpi_str(dpi) - icon.gsub! %r{res/(drawable|mipmap)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png" + icon.gsub!(%r{res/(drawable|mipmap)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png") end # we cannot prepare for any fallbacks but don't return nil for now to keep the behavior - # if want_png && icon.end_with?(".xml") Dir.mktmpdir do |dir| output_to = File.join(dir, icon) From 14b41efef38607659fe800a1c456a35ca1e8903c Mon Sep 17 00:00:00 2001 From: Jumpei Matsuda Date: Mon, 16 Dec 2019 17:26:09 +0900 Subject: [PATCH 2/2] Bump up version --- lib/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/version.rb b/lib/version.rb index b565e2e..3f1132d 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class AndroidApk - VERSION = "0.7.0" + VERSION = "1.1.0" end