How to update my game made with Unity running on Android? - android

My game have 100M asset bundles, I put the budle files into the StreamingAssets folder(I want to release my apk as one whole app, not the downloading when playing style), then I built my project into one apk file, then I installed the apk file to my device.
But how can I update my bundles when my game find one new update is available? The StreamingAssets folder on Android is read-only.
One solution is that: copy the bundles in the StreamingAssets folder to somewhere like the Android's External Storage, then use bundles in the External Storage. But this will increase my game size from 100M bundles to 200M.
So on Android when I install one apk, can I install some files meanwhile into somewhere writable?
Anyone can help me? Thanks.

Not sure if I understood: you shouldn't use asset bundles if you are not, at some point, going to update them or have new assets to download in-game.
So just use regular prefabs and use the regular Android update process to update the application.
But if you want to have asset updates in-game then you use asset bundles, put them on StreamingAssets and use WWW.LoadFromCacheOrDownload(string url, int version) to load them; when a new version of your asset is available you change the version in that call and it will just download and cache the new version.

Related

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.
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.

Android app update, assets update

I have an app and it uses .txt files from assets folder. In assets folder are more directories in some depth.
Later I will want to add new files to this assets folder so I'll have a new apk(cause files in assets are part of the apk).
The question: So what happens when someone, who is using my app, wants to update my app(with new files in assets) through Google Play, will it uninstall his old version and install the new one or how he receive these new files?
Or simpler: What happens during an app update?
Could someone make me keen vision in this a little? Thanks.
The old app is just replaced by the new app.
You don't have to worry about that. Apps are always installed completely without loosing data. That is, the .apk file is just replaced. So your assets will be also updated automatically.
Here an example:
Google Play Store downloads the new .apk file.
Next, it replaces the old apk file in /data/app/ by your new apk file.
That means that all the stuff that is in your new app is now available.
In this way the whole application is replaced.

Exporting of Android project - how to add a folder to .apk which will be installed too

(I am writing in Java and using libGDX as a framework, and i am using Eclipse)
So, i am using a images which are in assets folder, which probably does not exists, because if i export project as a .jar it does not create an assets folder, but the images are loaded in game, which is good(the .jar file probably includes a assets folder). but, this is my problem, i am creating a highscore saving, so, if i am trying to create a file: Highscore.bin to assets(game is exported and running) it does not save to there, so the highscore is not saved anywhere, so saving does not work. I tried to export it to .jar and created a folder to where it is creating a file and updating a file(C://pc//folder//highscore.bin. and i set the destination of saving highscore to : C://pc//folder//highscore.bin and it works! But on android, i actually cant add a folder to a mobile for every mobile individually. So my question is, how to create an .apk file(which installs you a game) that it will install a game, and that folder? If i am exporting it to .apk there is not a function which lets me to do this.
Thank you in advance
You cannot create any files in APK. APK and JAR are just archives and contain different information including classes and assets (You can try to open any jar or apk with any file archiver like WinZip). Most games are using device file system to store game resources and save files. Some code:
//Read
FileHandle file = Gdx.files.internal("savefile/highscore.txt");
if(file.exists()){
highscore = Float.valueOf(file.readString());
}
//Write
if(currentscore > highscore){
file.writeString(Float.toString(currentscore ),false);
}
But in most cases Preferences are better suited to store small numbers or strings in memory. Nice tutorial here: https://github.com/libgdx/libgdx/wiki/Preferences

Android SQlite external import/create

I have a database of questions from an external SQlite manager. I would like to create a database on the first run of my app.
Is this possible instead of writing hundereds of lines of code?
Yes, this is possible. You can put the SQLite file in the assets folder of your Android project (or download it on demand) and copy it to the database folder of the installed app.
A tutorial explaining all the neccesary steps can be found here.
Note however that if you include the database file into your APK, it will consume twice the disk space than absolutely necessary (since it will exist twice, as asset and as usable database). Depending on the size of your database, it might be preferable to download it instead of embedding it into the APK.
Note furthermore, that prior to Android 2.3, any compressed asset file with an uncompressed size of over 1 MB cannot be read from the APK (and any asset will be compressed by default).

Using not compiled media on Android

I'm developing an Android application. I'm very new on Android development.
I see on other projects that textures are hold on res directory. They have to be compiled and deployed into device.
I'm wondering if I can download a picture as a texture from a web service and use it.
I don't know if every media that I need has to be compiled.
Thanks.
Yes you could download the pictures from the web and use them. If you plan on having changeable content then you should probably do so as well.
Adding Images to Res will have them included in the APK and, Then copied to the device on installation (Unless you use zipalign which should sometimes allow you to use content from the apk)

Categories

Resources