Does Expansion Files stores all files into the res/drawable folder in my phone?

938 views Asked by At

I am new to android expansion files. I am not sure how it works or what to do (step-by-step build) an expansion file. As far I been reading, if I am not wrong please correct me; expansion files can be files that are stored in the Asset folder or Res folder. What I don't understand is if my app is depended on files that are stored in both folders and I take them out wouldn't that cause an error build? How does expansion really work? Furthermore, If I successfully create an expansion file from res folder (example) would the expansion file store it in the res folder in the phone? or I have to change all my code that makes reference to the res/drawable folder to the appropriate location? If so, then what is the correct path that I need to change my code into?

My app is so far like 600mb and continue to grow. Within my app, the core dependance is a database stored locally in the asset folder and some images in the res\drawable folder. There are some images that are not dependance on the app directly which makes the remaining 550mb. Nevertheless, those images are needed because the database makes reference to those images (just the name) then I populate an imageview with reference from the database. I was thinking to store all those images into an expansion file but I was not sure if those images will be store within the res/drawable folder in my phone or it will be store in a different folder? if so, would that cause an error?

1

There are 1 answers

0
ztan On BEST ANSWER

The expansion files are not supposed to save in your res folder. Res folder is part of your APK, so if you save your extra images in the res folder, your APK will still be over the 50MB limit.

From the Google Developer page, it states that "The expansion files are saved to the device's shared storage location (the SD card or USB-mountable partition; also known as the "external" storage) where your app can access them. On most devices, Google Play downloads the expansion file(s) at the same time it downloads the APK, so your application has everything it needs when the user opens it for the first time. In some cases, however, your application must download the files from Google Play when your application starts."

So, your expansion files should be saved in SD card. You can zip your images into a zip file, stored zip in your SD card, and read them while your application start.

You can use the APK expansion Zip Library and read the file from the zip. Sample code from Google Developer page:

// Get a ZipResourceFile representing a merger of both the main and patch files
ZipResourceFile expansionFile =
    APKExpansionSupport.getAPKExpansionZipFile(appContext,
        mainVersion, patchVersion);

// Get an input stream for a known file inside the expansion file ZIPs
InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);

You can read this documentation for more information about APK Expansion file. You can also find some tips from the Android developer blog about the APK Expansion file. Or you can visit this APK Expansion file tutorial.