Files generated by viewing a Realm with Realm Studio causes Gradle builds to hang
Goal
Ensure builds complete properly when bundling an existing Realm database with an Android application.
Actual Results
To bundle an existing Realm database with an Android application, the database file is often place in an /assets directory. If Realm Studio is used to inspect this database, a few files will be generated in the same directory, namely:
- A
.realm.lockfile. - A
.realm.notefile. - A
.realm.managementdirectory containing:- A
access_control.control.mxfile. - A
access_control.new_commit.cvfile. - A
access_control.pick_writer.cvfile. - A
access_control.write.mxfile.
- A
Attempting to build the application after these files have been generated in the /assets directory will cause the build to hang.
Steps & Code to Reproduce
- Create an Android application, and create an
/assetsdirectory inapp/src/main/. - Add a pre-exiting Realm database to the newly created
/assetsdirectory and rebuild the application, ensuring that it completes. - View the Realm database in
/assetswith Realm Studio, and observe the Realm specific files generated. - Attempt to rebuild and run the application, and note that the build hangs.
Version of Realm and tooling
Realm version(s): "io.realm:realm-gradle-plugin:5.4.2"
Realm Sync feature enabled: No
Android Studio version: 3.1.4
Android Build Tools version: 3.2.1
Gradle version: 4.6
Which Android version and device(s): N/A
Note: This issue is identical to #4787, which was closed last year. Please merge these issues as needed.
I'm not sure so this is something we can do anything about since this is Gradle acting up. Besides, you don't want to ship those files with your app anyway, so you should delete them from the /assets folder when done.
That said, I have noticed something similar so we should probably figure out exactly what is going on so we can report a bug report with Google.
@cmelchior This is a common issue during development of the application. Yes, the files may simply be deleted before building, however a common workflow is to view the contents of the database while writing application logic. These temporary files disrupt that workflow by (somehow) disrupting the mergeDebugAssets task during build time.
This issue was independently discovered by multiple Realm users, as shipping a local Realm database is somewhat common.
A Gradle task may be implemented to delete the files generated by Realm Studio before every build, though it would be preferable to simply have them be ignored. Perhaps a similar task can be included with the Realm plugin.
task cleanupRealm(type: Delete) {
delete project.projectDir.path + "/src/main/assets/appData.realm.management"
delete project.projectDir.path + "/src/main/assets/appData.realm.lock"
delete project.projectDir.path + "/src/main/assets/appData.realm.note"
}
tasks.whenTaskAdded { task ->
if (task.name == "preDebugBuild" || task.name == "preReleaseBuild") {
task.dependsOn cleanupRealm
}
}