Should We Remove The Room Migration DataBase Generated Schema files before App relase?

529 Views Asked by At

we are starting the room auto migrations.. now we are thinking is it possible to remove the generated Json Files of our database versions from relase the apk? im asking this because we have db structure for previous version and new version have its own db structure stored , and i can see these schema.jsnon files are only used in compile time to compare the db schema changes ..so is there a way to delete those files and generate a build?? the problem is each json file is almost 70kb and if there are like 100 versions its almost 7 mb.. which is not accepted from a design view and all the data is reduntant so should these shema.json files go through apk release???

i tried to remove those files and genrate a build but thats not happening,any one can help me in regarding this?

2

There are 2 best solutions below

0
Dev On BEST ANSWER

The generated json wont be part of generated build , but they are required for genrating the apk.

Practically -> I manually added 5 mb very large json to the schema folder so we can see the generated apk size difference , but its exactly the same.

Theoretically -> In the case of Room, the generated schema files are typically used during compilation to generate database-related code. Once the code generation is complete, the generated Java files are compiled along with the rest of your project's source code.

However, the schema files themselves (which are typically JSON files) are not needed at runtime. They are used by the Room annotation processor during compilation to generate the necessary database-related code but are not required by the application when it runs on a device.

Therefore, schema files are generally not included in the final APK. They are considered part of the build-time artifacts rather than the runtime assets. If you want to inspect or access the schema files during development or debugging, you might keep them in the project directory for reference, but they are not necessary for the functioning of the compiled application.

2
MikeT On

Should We Remove The Room Migration DataBase Generated Schema files before App relase?

The exported schemas are not included in the apk (I believe), rather the java generated from the exported schemas is part of the package.

It is the size of the compiled migrations that affects the size of the apk. As such you may wish to consider removing the automigrations. However, if the App is published then you have to consider the audience who may be behind in the uptake of versions.

Whether or not they can be deleted would depend upon the required version scope of the project.

Say you had an App that had progressed from 1 to 4 and you potentially had users of the App at all levels then you may want to have AutoMigrations:-

  • 1 to 2
  • 1 to 3
  • 2 to 3
  • 1 to 4
  • 2 to 4
  • 3 to 4

In which case the version scope would be from 1 to 4 and therefore you would need all 4 versions of the schema, otherwise the compile would fail.

The following is a screenshot of the above BUT 1.json has been effectively deleted (renamed) and then recompiled:-

enter image description here

Another consideration is that the exported schema could be useful as it can be used to ascertain the schema and even be used to build an empty database at any version.

  • as can be seen the _Impl's (generated java for the Migrations) lacks any of the from version 1's

Reintroducing (renaming xxx1.json to 1.json) and :-

enter image description here

To further elaborate, in the following the auto migrations that use version 1 (1 to 2, 1 to 3 and 1 to 4) have been commented out. Additionally the exported schema for version 1 has been effectively deleted (renamed). The compile works as it does not need to use version 1:-

enter image description here