Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Expansion File Location

We have a large ~600MB expansion file that we get using the Google Play Expansion APK mechanism. We also have to unzip this file for actual use. The entire app plus data thus requires about 1.4 GB of storage.

As far as I can tell Google Play insists of downloading the .obb to the "internal" SD and there doesn't appear to be any way to change this. We have many users with lots of free space on their "external" SD card but limited space on the internal one. They are screaming about the app taking so much space. Is there anything we can do about this?

We currently expand the .obb file to:

getExternalStorageDirectory()/Android/data

I suppose we could ask the user where they wanted it and they could choose the true external SD card. However that would still leave a (largely useless) .obb file on the internal SD card and Google Play says we cannot delete this.

Does anyone have any suggestions on how to handle this correctly?

like image 476
btschumy Avatar asked Oct 22 '22 15:10

btschumy


2 Answers

Per the Expansion File Storage Location documentation, expansion files are stored in

<shared-storage>/Android/obb/<package-name>/

where shared-storage is what is returned by getExternalStorageDirectory(), which should be on the SD card for users that have an SD card.

Unfortunately, as stated on that same page:

To ensure proper behavior, you must not delete, move, or rename the expansion files.

I would take special attention to this paragraph:

If you must unpack the contents of your expansion files, do not delete the .obb expansion files afterwards and do not save the unpacked data in the same directory. You should save your unpacked files in the directory specified by getExternalFilesDir(). However, if possible, it's best if you use an expansion file format that allows you to read directly from the file instead of requiring you to unpack the data. For example, we've provided a library project called the APK Expansion Zip Library that reads your data directly from the ZIP file.

like image 134
ianhanniballake Avatar answered Nov 15 '22 07:11

ianhanniballake


The problem with put OBB files in anywhere else is that they will not be removed when users uninstall your app, which tend to get them into a bad mood, to state it mildly. However if you believe the benefits outweigh the cost, there's nothing technical that stops you from changing the storage location, as the source code to perform OBB file(s) download & validation is provided, you can just modify its behavior to suite your needs.

For example, the path where OBB files are stored is provided by com.google.android.vending.expansion.downloader.Helpers:

static public String getSaveFilePath(Context c) {
    File root = Environment.getExternalStorageDirectory();
    String path = root.toString() + Constants.EXP_PATH + c.getPackageName();
    return path;
}

(Also needs to modify getFilesystemRoot(String path) & isFilenameValid(String filename))

If you are using Google's expansion zipfile lib as well, then you also need to change 3 methods in com.android.vending.expansion.zipfile.APKExpansionSupport that specify Environment.getExternalStorageDirectory() as the root dir.

These changes should at least get you half way there.

Also note that the problem with external SD card is that their speed vary greatly, it is usually that the internal SD would have at least decent speed. Maybe you can partition the OBB into 2 files (assuming you don't need the update file feature), and move one of them to external SD.

like image 34
Kai Avatar answered Nov 15 '22 05:11

Kai