hasen
hasen

Reputation: 166282

Developing an Android project with large assets; installing to device always takes a long time

I'm working on developing an Android application in Android Studio. I have large files in the assets folder, so the 'install' step of the code -> build -> install -> run cycle takes a long time, and I mean several minutes (5 to 10).

What's the best way to reduce that time?

The only idea I have is to use smaller assets data while developing.

The thing is the assets don't really change that often.

Are there any other ways to have the assets "pre-installed" so they don't have to be installed over and over again as part of the app (at least just while developing)

The asset folder consists of one large sqlite file, plus a myriad of image and sound files, that all add up to over 500MB.

Upvotes: 0

Views: 2121

Answers (1)

hasen
hasen

Reputation: 166282

I found it a nice way to do it using "Expansion packs" and "Opaque Binary Files" as described here:

https://developer.android.com/google/play/expansion-files.html

https://developer.android.com/studio/command-line/jobb.html

Here's how I did it:

1) Move everything from the assets folder to somewhere else.

Of course you are free to keep things in assets, but in my case I can do without them.

2) Use the jobb tool to create an obb file from your assets.

Assuming your package name is me.name.app

jobb -d appAssets -o main.1.me.name.app.obb -pn me.name.app -pv 1

You might have to change -pv depending on your package version.

The naming chosen here main.1.me.name.app.obb is not arbitrary; it's what the Play Store will rename your file to when you upload it. See the File Name section of the docs.

3) Figure out where you should place your obb file. This is the path that Android will place your file in when the app is downloaded from the play store. I haven't deployed it to the play store yet so for all I know there could be some mistake in this step.

The path to the obb is described in the documentation as <shared-storage>/Android/obb/<package-name>/ where <shared-storage> can be obtained from Environment.getExternalStorageDirectory() and package-name is me.name.app as per our example, so the path to the obb would be:

Environment.getExternalStorageDirectory() + "/Android/obb/me.name.app/main.1.me.name.app.obb"

On my Android, the external store seems to be at "/storage/emulated/0/" but I would assume it could be different across devices.

Once you find out where the path should be, place your obb file there.

4) In your app, use StoreManager.mountObb to mount the obb to a new root path. Store this root path in a global object and use it across your application's code.

You have to go through your code and change any part that relies on the AssetsManager and change it to use regular file paths.

Your app (apk) file size is now much smaller but you still get to access your assets.

Upvotes: 1

Related Questions