To then change the default behavior of the ObjectBox plugin and processor read on for advanced setup options.
Manually Add Libraries
The ObjectBox Gradle plugin adds required libraries and the annotation processor to your projects dependencies automatically, but you can also add them manually.
Just make sure to apply the ObjectBox Gradle plugin after the dependencies block, so it does not replace manually added dependencies.
In your app's Gradle build script:
dependencies {// All below added automatically by the plugin:// Java libraryimplementation("io.objectbox:objectbox-java:$objectboxVersion")// Kotlin extension functionsimplementation("io.objectbox:objectbox-kotlin:$objectboxVersion")// Annotation processorkapt("io.objectbox:objectbox-processor:$objectboxVersion")// Native library for Androidimplementation("io.objectbox:objectbox-android:$objectboxVersion")}// Apply plugin after dependencies block so they are not overwritten.apply plugin:'io.objectbox'// Or using Kotlin DSL:apply(plugin ="io.objectbox")
dependencies {// All below added automatically by the plugin:// Java libraryimplementation("io.objectbox:objectbox-java:$objectboxVersion")// Annotation processorannotationProcessor("io.objectbox:objectbox-processor:$objectboxVersion")// Native library for Androidimplementation("io.objectbox:objectbox-android:$objectboxVersion")}// Apply plugin after dependencies block so they are not overwritten.apply plugin:'io.objectbox'// Or using Kotlin DSL:apply(plugin ="io.objectbox")
dependencies {// All below added automatically by the plugin:// Java library implementation("io.objectbox:objectbox-java:$objectboxVersion")// Annotation processor annotationProcessor("io.objectbox:objectbox-processor:$objectboxVersion")// One of the native libraries required for your system implementation("io.objectbox:objectbox-linux:$objectboxVersion") implementation("io.objectbox:objectbox-macos:$objectboxVersion") implementation("io.objectbox:objectbox-windows:$objectboxVersion")// Not added automatically:// Since 2.9.0 we also provide ARM support for the Linux library implementation("io.objectbox:objectbox-linux-arm64:$objectboxVersion") implementation("io.objectbox:objectbox-linux-armv7:$objectboxVersion")}// Apply plugin after dependencies block so they are not overwritten.apply plugin: "io.objectbox"// Or using Kotlin DSL:apply(plugin ="io.objectbox")
dependencies {// All below added automatically by the plugin:// Java library implementation("io.objectbox:objectbox-java:$objectboxVersion")// Kotlin extension functions implementation("io.objectbox:objectbox-kotlin:$objectboxVersion")// Annotation processor kapt("io.objectbox:objectbox-processor:$objectboxVersion")// One of the native libraries required for your system implementation("io.objectbox:objectbox-linux:$objectboxVersion") implementation("io.objectbox:objectbox-macos:$objectboxVersion") implementation("io.objectbox:objectbox-windows:$objectboxVersion")// Not added automatically:// Since 2.9.0 we also provide ARM support for the Linux library implementation("io.objectbox:objectbox-linux-arm64:$objectboxVersion") implementation("io.objectbox:objectbox-linux-armv7:$objectboxVersion")}// Apply plugin after dependencies block so they are not overwritten.apply plugin: "io.objectbox"// Or using Kotlin DSL:apply(plugin ="io.objectbox")
For JVM apps, by default, the ObjectBox Gradle plugin only adds the native (Linux, macOS or Windows) library required to run on your current system. If your app wants to support multiple platforms, manually add all of the required native libraries listed above when you distribute your app.
Processor Options
In your app’s Gradle build script, the following processor options, explained below, are available:
By default, the ObjectBox model file is stored in module-name/objectbox-models/default.json. You can change the file path and name by passing the objectbox.modelPath argument to the ObjectBox annotation processor.
Change the MyObjectBox package
Since 1.5.0
By default, the MyObjectBox class is generated in the same or a parent package of your entity classes. You can define a specific package by passing the objectbox.myObjectBoxPackage argument to the ObjectBox annotation processor.
Enable Debug Mode
You can enable debug output for the annotation processor if you encounter issues while setting up your project and entity classes.
In your app’s build.gradle file, enable the objectbox.debug option and then run Gradle with the --info option to see the debug output.
To enable debug mode for the ObjectBox Gradle plugin:
// Enable debug output for the plugin// Groovy DSLobjectbox { debug =true}// Kotlin DSLconfigure<io.objectbox.gradle.ObjectBoxPluginExtension> { debug.set(true)}
Enable DaoCompat mode
ObjectBox can help you migrate from greenDAO by generating classes with a greenDAO-like API.
To customize the directory (relative to the package root) where the files generated by ObjectBox are written, add the following to your pubspec.yaml:
objectbox:
# Writes objectbox-model.json and objectbox.g.dart to lib/custom (and test/custom).
output_dir: custom
# Or optionally specify the lib and test output folder separately.
# output_dir:
# lib: custom
# test: other