Use unzip as fallback when apktool fails
apktool used in apk comparator can fail for various reasons (upstream have many related bugs, mostly because of obfuscated apks trying to avoid decompilations), example of failed apktool command in the past: https://verification.f-droid.org/org.telegram.messenger_11575.apk.diffoscope.html
so a fallback to using unzip when apktool failed is needed to avoid showing binary output like in above result.
currently it's possible to test by using the apk from upstream issue in: https://github.com/iBotPeaches/Apktool/issues/2195 The below file:
https://wap.pp.cn/app/dl/fs08/2019/11/07/11/106_039ea82f26db61aa480f9000620c78f1.apk
will fail decompilation, so using it in diffoscope (copy it and add or remove file inside it to compare with original version) will result in binary diff, for example:
Exception in thread "main" java.lang.NullPointerException
at brut.androlib.res.data.value.ResEnumAttr.serializeBody(ResEnumAttr.java:56)
at brut.androlib.res.data.value.ResAttr.serializeToResValuesXml(ResAttr.java:64)
at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:742)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:263)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:129)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:124)
at brut.apktool.Main.cmdDecode(Main.java:170)
at brut.apktool.Main.main(Main.java:76)
2020-05-18 20:18:40 D: diffoscope.comparators.utils.command: Executing xxd {}
2020-05-18 20:18:47 D: diffoscope.comparators.utils.command: Executing xxd {}
2020-05-18 20:18:55 D: diffoscope.diff: Running diff -aU7 /tmp/diffoscope_f8nbxwzd/tmp1tw44ny9/fifo1 /tmp/diffoscope_f8nbxwzd/tmp1tw44ny9/fifo2
2020-05-18 20:18:59 D: diffoscope.diff: diff -aU7 /tmp/diffoscope_f8nbxwzd/tmp1tw44ny9/fifo1 /tmp/diffoscope_f8nbxwzd/tmp1tw44ny9/fifo2: returncode 1, parsed True
2020-05-18 20:18:59 D: diffoscope.presenters.formats: Generating 'text' output at '-'
--- /ifiles/106_039ea82f26db61aa480f9000620c78f1.apk
+++ /ifiles/106_039ea82f26db61aa480f9000620c78f1-copy.apk
│┄ Command `apktool d -k -m -o /tmp/diffoscope_f8nbxwzd/tmp3wrx08r1/106_039ea82f26db61aa480f9000620c78f1.apk /ifiles/106_039ea82f26db61aa480f9000620c78f1.apk` exited with exit code 1. (No output)
@@ -93,8 +93,8 @@
000005c0: bc43 ed4a 497c 417d e724 e653 b172 128f .C.JI|A}.$.S.r..
000005d0: 509c 96c4 0cca 5749 e213 86a5 2731 97ea P.....WI....'1..
fix: if apktool fail (command not exists / command return error, failed-to-find-diff?) use unzip instead and ensure that it still show the unrelated metadata from other tools (such as recently introduced apksigner and zipinfo
information)