Bug in APK Expansion Zip Library for Android, patch not working

Andrey Nikishaev
1 min readSep 8, 2016
static String[] getAPKExpansionFiles(Context ctx, int mainVersion, int patchVersion) {
String packageName = ctx.getPackageName();
Vector < String > ret = new Vector < String > ();
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
// Build the full path to the app's expansion files
File root = Environment.getExternalStorageDirectory();
String path = Build.VERSION.SDK_INT >= 23 ? EXP_PATH_API_23 : EXP_PATH;
File expPath = new File(root.toString() + path + packageName);
// Check that expansion file path exists
if (expPath.exists()) {
if (mainVersion > 0) {
String strMainPath = expPath + File.separator + "main." + mainVersion + "." + packageName + ".obb";
File main = new File(strMainPath);
if (main.isFile()) {
ret.add(strMainPath);
}
}
if (patchVersion > 0) {
String strPatchPath = expPath + File.separator + "patch." + mainVersion + "." + packageName + ".obb";
File main = new File(strPatchPath);
if (main.isFile()) {
ret.add(strPatchPath);
}
}
}
}
String[] retArray = new String[ret.size()];
ret.toArray(retArray);
return retArray;
}

So if you looks at line where constructed strPatchPath you will see that instead of patchVersion it uses mainVersion. So if you are using this library, dont forget to change it to patchVersion.

Don’t forget to checkout my new Android App for removing stress: http://goo.gl/Iz8r5u

--

--