Search code examples
androidcompressionembedded-resource

Adding a big text file to assets folder


I'm developing an Android 2.2 application.

I want to add some big text files (4.5MB or more) to Android project.

First I don't know if I can add such kind of big files to assets folder. But, if I can, is it possible to compress them?

How can I compress files? and decompress?

Any other better way to add big text files to Android project?

Thanks.


Solution

  • Files over 1 MB placed in the assets folder won't be readable from your app (It'll throw an exception). This is because they get compressed during the build process, and thus the phone requires substantial resources to uncompress them when on the handset.

    I believe you can place them in the raw folder, where they won't get compressed or use an extension that AAPT assumes is already compressed (see here)

    However, It's not good having a 4.5 MB text file uncompressed sitting in the APK, It's wasted space that could be handled better. Try thinking about downloading the data on first use instead, or splitting the file into chunks as suggested before so that AAPT can compress it.