Realm.io/Dagger/Databinding in the same project

I am having problems compiling my project after adding Realm.io as a dependency via gradle. Generated files created by a dagger and data binding cannot be found. If I remove realm.io, the application compiles correctly.

Here is my build.gradle

apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'com.android.databinding' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { multiDexEnabled true applicationId "com.foo" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.facebook.stetho:stetho:1.2.0' compile 'com.facebook.stetho:stetho-okhttp:1.2.0' compile 'io.reactivex:rxandroid:0.24.0' compile 'io.reactivex:rxjava:1.0.14' compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.okio:okio:1.4.0' compile 'com.google.code.gson:gson:2.3' compile 'com.jakewharton:butterknife:6.1.0' compile 'com.android.support:recyclerview-v7:23.1.0' compile 'com.squareup.picasso:picasso:2.3.2' compile 'com.android.support:cardview-v7:23.1.0' compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:design:23.1.0' compile 'com.jakewharton.timber:timber:4.1.0' compile 'io.realm:realm-android:0.85.1' compile 'com.google.dagger:dagger:2.0.1' provided 'javax.annotation:jsr250-api:1.0' apt "com.google.dagger:dagger-compiler:2.0.1" apt 'com.android.databinding:compiler:1.0-rc4' } 

Error

I see that Realm also creates files, and maybe the compilers do not play well together. Any ideas on how to do this?

thanks

+5
source share
4 answers

I see that you also received an error message:

No setter found for goal field goal

Make sure the field names match the names of the recipients and setters. Do not add "m" to field names. Example:

 @RealmClass public Goal extends RealmObject { //private String mGoalInfo; private String goalInfo; public String getGoalInfo() { return goalInfo; } public void setGoalInfo(String goalInfo) { this.goalInfo = goalInfo; } } 
+2
source

Working with data with RealmObjects , but you have to implement Observable.

 public class Post extends RealmObject implements Observable { @PrimaryKey private long id; private String text; @Ignore private transient PropertyChangeRegistry mCallbacks; @Bindable public long getId() { return id; } public void setId(long id) { this.id = id; if(!isValid()) { // !isManaged() in Realm 2.0 notifyPropertyChanged(BR.id); } } @Bindable public String getText() { return text; } public void setText(String text) { this.text = text; if(!isValid()) { // !isManaged() in Realm 2.0 notifyPropertyChanged(BR.text); } } @Override public synchronized void addOnPropertyChangedCallback(OnPropertyChangedCallback callback) { if (mCallbacks == null) { mCallbacks = new PropertyChangeRegistry(); } mCallbacks.add(callback); } @Override public synchronized void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) { if (mCallbacks != null) { mCallbacks.remove(callback); } } /** * Notifies listeners that all properties of this instance have changed. */ public synchronized void notifyChange() { if (mCallbacks != null) { mCallbacks.notifyCallbacks(this, 0, null); } } /** * Notifies listeners that a specific property has changed. The getter for the property * that changes should be marked with {@link Bindable} to generate a field in * <code>BR</code> to be used as <code>fieldId</code>. * * @param fieldId The generated BR id for the Bindable field. */ public void notifyPropertyChanged(int fieldId) { if (mCallbacks != null) { mCallbacks.notifyCallbacks(this, fieldId, null); } } } 

And Dagger + Databinding can break each other, for which you need to add

 apt 'com.google.guava:guava:19.0' // dagger + databind workaround 
+2
source

Realm, Dagger2 and Databinding work in my project.

The difference is as follows:

I use android gradle plugin 1.5.0 and activate data binding with the following configuration.

 android { ... dataBinding { enabled = true } ... } 

And i don't have

 apt 'com.android.databinding:compiler:1.0-rc4' 

in dependencies.

The whole working draft is here: https://github.com/zaki50/realm_template

+1
source

Now you can implement the RealmModel interface and add the @RealmClass annotation to the class instead of the RealmObject extension. This allows you to extend BaseObservable, but it still does not work.

You get a data binding error: mypackage.databinding package does not exist

See this issue on github: https://github.com/realm/realm-java/issues/2716

0
source

Source: https://habr.com/ru/post/1236817/


All Articles