Hello I recently decided to add ObjectBox plugin to my existing project since I’ve been using it in other projects and I like it very much.
I am adding and applying the plugin as always and as its indicated in the Getting Started doc.
This is the project build.graddle buildscript:
buildscript {
ext.kotlin_version = '1.9.23'
ext.dagger_version = '2.51.1'
ext.objectbox_version = '3.8.0'
repositories {
maven { url 'https://jitpack.io' }
google()
mavenCentral()
jcenter() // Consider removing jcenter as it's deprecated.
}
dependencies {
classpath 'com.android.tools.build:gradle:8.3.0' // 8.3.0 best for SDK 34.
// Plugins
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$dagger_version"
classpath "io.objectbox:objectbox-gradle-plugin:$objectbox_version"
}
}
Now this is the application build.graddle:
plugins {
id 'com.android.application'
id 'kotlin-parcelize'
id 'dagger.hilt.android.plugin'
id 'io.objectbox' // Apply last always.
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'io.objectbox' // Apply last always.
android {
compileSdk 34 // SDK Version
// Rest of the code...
}
This works so far in my App since when I open a Java class it imports correctly the io.objectbox library classes.
The thing is I’m declaring an Entity in order to generate the database but when I make the project it does nothing and doesn’t generate the database files for example the objectbox-models folder is not being generated.
Here’s the first Entity that I have created to generate the ObjectBox database.
import com.google.gson.annotations.Expose;
import io.objectbox.annotation.Entity;
import io.objectbox.annotation.Id;
import io.objectbox.annotation.Uid;
@Entity
public class Usuario {
@Id private long idBoxStore;
@Expose private long id;
@Expose private String username;
@Expose private String password;
@Expose private boolean active;
@Expose private String bearer_token;
public Usuario() {
}
public long getIdBoxStore() {
return idBoxStore;
}
public void setIdBoxStore(long idBoxStore) {
this.idBoxStore = idBoxStore;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getBearerToken() {
return bearer_token;
}
public void setBearerToken(String token) {
this.bearer_token = token;
}
}
I tried creating a BoxStoreManager class in order to define the Boxes and create methods for specific querys. It would be an instance of the ObjectBoxBuilder BoxStore. Here’s an example of the method that has the conflict. It cannot recognize what is MyObjectBox.
private static void updateBoxStoreIfNeeded(Context context) {
if (boxStore == null || boxStore.isClosed()) {
boxStore = MyObjectBox.builder().androidContext(context.getApplicationContext()).build();
}
}
This and not seing the generated files just makes me belive that it’s not working properly.
Am I missing a step? I’m pretty sure I followed a step by step guide from the Getting Started official documentation. But as you can see I cannot get past the ‘Generate ObjectBox code’ step.