From 3a33bfc48f22800ce7083d618deac9502fb7c068 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Thu, 19 Apr 2018 17:09:44 -0400 Subject: [PATCH] fix: allow detection of aapt2 from old SDK builds --- .../src/main/java/brut/util/AaptManager.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/brut.j.util/src/main/java/brut/util/AaptManager.java b/brut.j.util/src/main/java/brut/util/AaptManager.java index 129e6361..ed305af1 100644 --- a/brut.j.util/src/main/java/brut/util/AaptManager.java +++ b/brut.j.util/src/main/java/brut/util/AaptManager.java @@ -82,6 +82,18 @@ public class AaptManager { return "aapt" + (version == 2 ? "2" : ""); } + public static int getAppVersionFromString(String version) throws BrutException { + if (version.startsWith("Android Asset Packaging Tool (aapt) 2:")) { + return 2; + } else if (version.startsWith("Android Asset Packaging Tool (aapt) 2.")) { + return 2; // Prior to Android SDK 26.0.2 + } else if (version.startsWith("Android Asset Packaging Tool, v0.")) { + return 1; + } + + throw new BrutException("aapt version could not be identified: " + version); + } + public static int getApptVersion(File aapt) throws BrutException { if (!aapt.isFile()) { throw new BrutException("Could not identify aapt binary as executable."); @@ -98,12 +110,6 @@ public class AaptManager { throw new BrutException("Could not execute aapt binary at location: " + aapt.getAbsolutePath()); } - if (version.startsWith("Android Asset Packaging Tool (aapt) 2:")) { - return 2; - } else if (version.startsWith("Android Asset Packaging Tool, v0.")) { - return 1; - } - - throw new BrutException("aapt version could not be identified: " + version); + return getAppVersionFromString(version); } }