Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Asset file not upgraded on app upgrade

Tags:

android

In my Android application, I have some configuration for a library in a text file called library.cfg. This file lives in assets\library in my Android Studio project. (Both the application and library are proprietary, so I can't divulge more details).

I install the app with on our target device (which is running 2.3.4 Gingerbread, if that is relevant). The library.cfg file appears correctly.

I edit the library.cfg file to include a new setting value.

I then install the app again with the same signing config, but an incremented version name/code. The new APK includes the new settings in the asset file.

If I only install the app, the changes to library.cfg are not reflected by the copy of the file at /data/data/com.myapp.package/library/library.cfg. The file is the same as in the original install.

If I uninstall the app and then install the second build of the app with the updated config file, /data/data/com.myapp.package/library/library.cfg contains the added values.

Why isn't the file updated when I upgrade the app rather than uninstalling/reinstalling? What do I have to do to ensure that the file is updated during upgrade?

like image 496
emerssso Avatar asked Sep 27 '22 17:09

emerssso


1 Answers

Open the file with Context.getAssets() on each startup of the app, when upgrade the app, first launch it and after that check if the file has change.

Its seems that until you access the file, it is not extracted from the apk to /data/data/<your-package>/

like image 145
Omar Mainegra Avatar answered Oct 13 '22 00:10

Omar Mainegra