/** * Parses the aapt output and returns an ApkInfo object. * @param aaptOutput the aapt output as a list of lines. * @return an ApkInfo object. */ @VisibleForTesting @NonNull static ApkInfo getApkInfo(@NonNull List<String> aaptOutput) { String pkgName = null, versionCode = null, versionName = null; for (String line : aaptOutput) { Matcher m = PATTERN.matcher(line); if (m.matches()) { pkgName = m.group(1); versionCode = m.group(2); versionName = m.group(3); break; } } if (pkgName == null) { throw new RuntimeException("Failed to find apk information with aapt"); } Integer intVersionCode = null; try { intVersionCode = Integer.parseInt(versionCode); } catch(NumberFormatException ignore) { // leave the version code as null. } return new ApkInfo(pkgName, intVersionCode, versionName); }
/** * Parses the aapt output and returns an ApkInfo object. * @param aaptOutput the aapt output as a list of lines. * @return an ApkInfo object. */ @VisibleForTesting @NonNull static ApkInfo getApkInfo(@NonNull List<String> aaptOutput) { String pkgName = null, versionCode = null, versionName = null; for (String line : aaptOutput) { Matcher m = PATTERN.matcher(line); if (m.matches()) { pkgName = m.group(1); versionCode = m.group(2); versionName = m.group(3); break; } } if (pkgName == null) { throw new RuntimeException("Failed to find apk information with aapt"); } Integer intVersionCode = null; try { intVersionCode = Integer.parseInt(versionCode); } catch(NumberFormatException ignore) { // leave the version code as null. } return new ApkInfo(pkgName, intVersionCode, versionName); }