Objectbox-java: [0.9.14] Android flavors cause model file to be in wrong dir

Created on 17 Aug 2017  路  22Comments  路  Source: objectbox/objectbox-java

i run my app with objectbox, and populate database
in next run i must clean my project, and rebuild and run,
in next run this exception occurred, this is bug or normal behavior ?
if normal, this is problem, sometimes developer need clean project, what do need for that ?
thanks

Unable to create application ****: io.objectbox.exception.DbException: Incoming entity ID 4:322973086687871121 does not match existing UID 430538273810174192
bug

All 22 comments

My first guess would be that you renamed an Entity. If that is the case, you should get familiar with @Uid. In your case, try putting @Uid(322973086687871121L) on your entity. Thus, it can match the entity. For more background, you can check the docs on UIDs and renames.

We will improve error handling on our side to give some more guidance. Thanks for your continued support!

no, i just (Build > Clean Project) and run project !

What happens when you use @Uid(322973086687871121L) on the entity?

Error:[ObjectBox] Could not sync parsed model with ID model file "objectbox-models/default.json": No entity with UID 322973086687871121 found

@DJafari Oh sorry, I took the wrong one. Try @Uid(430538273810174192L)

i have multiple Entities
i set @Uid to all models from app/build/objectbox-models/default.json values

but when build project return this error :

Error:[ObjectBox] Could not sync parsed model with ID model file "app/build/objectbox-models/default.json": No entity with UID 1877565599078586064 found

this is part of my default.json :

"entities": [
  {
    "id": "1:1877565599078586064",
    "lastPropertyId": "6:3824731825341338928",
    "name": "NewsCategory"
  },
  {
    "id": "2:1317890954678390256",
    "lastPropertyId": "5:1169169540594985464",
    "name": "NewsGroup"
  },
  {
    "id": "3:5616009236255126928",
    "lastPropertyId": "6:1572936764897749516",
    "name": "NewsOption"
  },
  {
    "id": "4:3680703494710125769",
    "lastPropertyId": "4:6906762574723081504",
    "name": "Page"
  }
],
@Entity
@Uid(1317890954678390256L)
public class NewsGroup {
}
@Entity
@Uid(1877565599078586064L)
public class NewsCategory {
}
@Entity
@Uid(3680703494710125769L)
public class Page {
}
@Entity
@Uid(5616009236255126928L)
public class NewsOption {
}

i found problem
because new location of default.json is in app/build folder, after clean project objectbox-models deleted automatically !

@DJafari How did default.json end up in app/build? Are you saying that it is generated by the ObjectBox build tools at that place?

yes, objectbox 0.9.14 generated it automatically after build in this folder, in 0.9.13 this folder created in app folder

@DJafari OK, that's an interesting find. Is there anything special in your directory structure?

no, it's default structure, but i have multi flavor gradle setting, and include another library project in setting.gradle

this is my gradle files :

root/build.gradle

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url "http://objectbox.net/beta-repo/" }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta2'
        classpath 'com.google.gms:google-services:3.1.0'
        classpath 'io.objectbox:objectbox-gradle-plugin:0.9.14'
        classpath 'com.google.firebase:firebase-plugins:1.1.1'
    }
}

ext {
    minSdkVersion = 15
    targetSdkVersion = 26
    compileSdkVersion = 26
    buildToolsVersion = "26.0.0"
    supportLibVersion = "26.0.0"
    constraintLayoutVersion = "1.0.2"
    firebaseVersion = "11.2.0"
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

root/setting.gradle

include ':app'
include ':Commons'
project(':Commons').projectDir = new File('../Commons/app')

app/build.gradle

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'io.fabric'
apply plugin: 'io.objectbox'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        useLibrary 'org.apache.http.legacy'

        flavorDimensions "app"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        app1 {
            dimension "app"

            applicationId "com.test.app"
            versionCode 400
            versionName "4.00"

            signingConfig signingConfigs.test

            manifestPlaceholders = [fabricAPI: "*******"]
        }
    }
}

repositories {
    jcenter()
    maven { url 'https://maven.google.com' }
    maven { url "http://objectbox.net/beta-repo/" }
}

dependencies {
    compile project(':Commons')

    compile 'com.google.firebase:firebase-perf:11.2.0'
    compile('com.crashlytics.sdk.android:crashlytics:+@aar') {
        transitive = true
    }
    compile 'io.objectbox:objectbox-android:0.9.14'

}

apply plugin: 'com.google.gms.google-services'

yes problem is flavors, i define a flavor to new project that objectbox-models is correct location, after define new flavor, this project make objectbox-models in app/build folder

@DJafari Great, thanks for tracking it down! Helps a lot!

you're welcome, i have thank from your great library and support !
is this known to when this bug fixed ?

sorry, i have idea for location of objectbox-model folder

in app folder, if exists a folder equal of flavor, it's to be good that objectbox-model folder generated in this folder. because sometimes i need add a entity just for a flavor, objectbox-models must be different from another flavors

sample if i have a flavor with name testApp, if exists app/testApp, location of objectbox-models must be : app/testApp/objectbox-models

this folder structure may be with buildType

thanks

@DJafari Can you tell a bit more how you use flavors and why your entity model differs among flavors?

There is a downside to having a model per flavor: if you share the app ID among flavors you cannot switch without clearing the app data. This is because diverging schema are not compatible to each other (UIDs differ and potentially also IDs).

Because of this we thought it would be a good idea to have a common entity model across flavors. Even if that means that some entities will be around for no use in some flavors.

you say right, but in other case developer need this feature
i have a single structure app with multiple flavor, that each flavor have own package id, version and ...
in each flavor i set colors and webservice urls, sometime need i have a entitiy only for one flavor ( one app ) and don't need for others
i think each flavor has own objectbox-models not faced up any problem, if change build variant in android studio, gradle must use from own objectbox-models

The bug is fixed that ObjectBox uses the wrong dir when using flavors. Other than that we deferred "model per flavor" to #149

@DJafari 0.9.15 is out - can you verify it resolves the issue? Thanks!

@greenrobot thanks, no problem, everythings is ok

i have a in development app, i want use objectbox as main database library, but reported relation bugs annoying me, is possible to say when this bugs fixed ?

or if want too many time, i must use greendao

@DJafari Thanks again! Any other than #150 bothering you? Will push out another bugfix release soon.

@greenrobot yes this is one bug that i found it,
but many things is feature, like greendao

@Order for too many relation
set foreign ids to relation, example from greendao :

    @ToMany
    @JoinEntity(
            entity = JoinProductsWithOrders.class,
            sourceProperty = "productId",
            targetProperty = "orderId"
    )
    private List<Order> ordersWithThisProduct;

p.s: eager load is too much need, if i want, load all relation fields automatically in same thread that run query

if need i open issue per feature

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndSync picture AndSync  路  16Comments

greenrobot picture greenrobot  路  17Comments

DJafari picture DJafari  路  21Comments

DJafari picture DJafari  路  29Comments

greenrobot picture greenrobot  路  56Comments