[Android] Saved data are erased by "cocos compile"

Hi.

I’m developing a game by cocos2d-x -l cpp.
I’m trouble android’s develop.

When I do “cocos run -p android -m debug”, but, it does uninstall and then install my app in fact.
Once an app is uninstalled, the data of the app are erased.
The data are stored by std::ofstream or FileUtils::writeToFile.

I want to update my developing app, but, don’t want to erase data every compilation.
How can I do?

1 Like

every time an app is uninstalled its directory get erased from the device as I understand it. :slight_smile:

Try editing tools/cocos2d-console/plugins/project_deploy.py to be this (around line 197)

   #TODO detect if the application is installed before running this
   # adb_uninstall = "%s uninstall %s" % (adb_path, self.package)
   # self._run_cmd(adb_uninstall)
   adb_install = "%s install -r \"%s\"" % (adb_path, apk_path)
   self._run_cmd(adb_install)
1 Like

Thanks!
I’ll try now.

IslandPlaya’s solution is so nice.
Solved!

But, wouldn’t that be a bad idea !!

The game data should be destroyed once the app is un-installed.
Can you sight me an example, how not deleting the data would help and in which scenario will it help… :smile:

You are confused.
The change to the script merely stops the app being uninstalled and re-installs instead using the -r flag whilst developing.
If the end-user uninstalls the app from their device then both the app and it’s data are removed.

1 Like

Exactly. I don’t think anyone would want to develop if their data would be wiped between every reinstall… as is currently the case with the cocos command :frowning:

I think your fix should be the default behavior when running “cocos run -p android”, or at least an option… can someone propose that? That is the default behavior of iOS anyway :slight_smile: