Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 同一项目中的Realm.io/Dagger/Databinding_Android_Realm_Dagger 2_Android Databinding - Fatal编程技术网

Android 同一项目中的Realm.io/Dagger/Databinding

Android 同一项目中的Realm.io/Dagger/Databinding,android,realm,dagger-2,android-databinding,Android,Realm,Dagger 2,Android Databinding,在通过gradle将Realm.io添加为依赖项后,我在编译项目时遇到问题。找不到由dagger和数据绑定创建的生成文件。如果我删除realm.io,应用程序将正确编译 这是我的身材,格雷德尔 apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'com.android.databinding' android { compileSdkVersion

在通过gradle将Realm.io添加为依赖项后,我在编译项目时遇到问题。找不到由dagger和数据绑定创建的生成文件。如果我删除realm.io,应用程序将正确编译

这是我的身材,格雷德尔

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'
}

我看到Realm也在生成文件,也许编译器在一起玩得不好。有什么办法让它工作吗


谢谢,领域、匕首2和数据绑定都在我的项目中工作

区别在于:

我正在使用android gradle插件1.5.0,并通过以下配置启用数据绑定

android {
    ...
    dataBinding {
        enabled = true
    }
    ...
}
而我没有

apt 'com.android.databinding:compiler:1.0-rc4'
在依赖项中


整个工作项目都在这里:

我看到您也收到了错误:

未找到字段goalInfo的setter

确保字段名与getter和setter相同。不要在字段名前加“m”。例如:

@RealmClass
public Goal extends RealmObject {
    //private String mGoalInfo;
    private String goalInfo;

    public String getGoalInfo() {
        return goalInfo;
    }

    public void setGoalInfo(String goalInfo) {
        this.goalInfo = goalInfo;
    }
}

现在可以实现realmodel接口并向类添加注释@RealmClass,而不是扩展RealmObject。这允许您扩展BaseObservable,但它仍然不起作用

出现数据绑定错误:包mypackage.databinding不存在

请参见github上的这个问题:

,但是您必须实现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);
        }
    }
}
Dagger+数据绑定可以互相破坏,为此您需要添加

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

是的,Realm的注释处理器正在创建代理类,这些代理类也在构建期间编译。在屏幕截图中,这些错误似乎与Realm以外的其他类有关。如果你删除了Realm,你的应用程序会生成吗?是的,我删除了Realm。在将android gradle插件更新为2.0.0,将Realm更新为0.88.3后,应用程序会生成Fine,你能生成成功吗?不工作。它显示相同的错误包不存在exists@LuvnishMonga这可能意味着您的代码中有一些错误,而代码工作正常。我只使用数据绑定和领域。当我的模型类扩展到RealmObject时,它显示了@Darussian所面临的相同错误。当我实现你的代码时,它显示了同样的错误。@EpicPandaForce什么时候我们应该使用
实现可观察的
实现可观察的
实现可观察的,可观察的
?什么是
可观察的
?但是,添加了
RealmDataBinding
接口以支持侦听托管对象