Tuesday, 4 December 2018

Exclude temporary Realm files from Gradle build

Realm provides a database viewer called "Realm Studio" that allows users to browse the contents of their database. When the application is used to view a database, it creates several "temporary" files in the directory of the database, namely:

  • A .realm.lock file.
  • A .realm.note file.
  • A .realm.management directory containing:
    • A access_control.control.mx file.
    • A access_control.new_commit.cv file.
    • A access_control.pick_writer.cv file.
    • A access_control.write.mx file.

In the context of Android, a preexisting Realm database is sometimes shipped with an application by placing the database in the /assets directory. Thus, when the Realm Studio is used to view this database, the aforementioned files are generated in /assets. For unknown reasons, this causes Gradle to hang indefinitely at the :app:generateDebugAssets task.

As such, i'd like to find a way to exclude these files from the build. I've tried several methods, such as:

applicationVariants.all { variant ->
    if (variant.buildType.name == 'debug') {
        variant.mergeAssets.doLast {
            delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['**/*.cv', '**/*.mx', '**/*.lock', '**/*.note']))
        }
    }
}

and other methods, like:

sourceSets.main.assets.exclude 'appData.realm.management'
sourceSets.main.assets.exclude 'appData.realm.management/access_control.control.mx'
sourceSets.main.assets.exclude 'appData.realm.management/access_control.new_commit.cv'
sourceSets.main.assets.exclude 'appData.realm.management/access_control.pick_writer.cv'
sourceSets.main.assets.exclude 'appData.realm.management/access_control.write.mx'
sourceSets.main.assets.exclude 'appData.realm.lock'
sourceSets.main.assets.exclude 'appData.realm.note'

to no avail.

How can one instruct Gradle to exclude these files when running a build?



from Exclude temporary Realm files from Gradle build

No comments:

Post a Comment