2015-11-25 13 views
5

Tôi đang gặp vấn đề với việc biên dịch dự án của mình sau khi tôi thêm Realm.io làm phụ thuộc thông qua gradle. Không thể tìm thấy các tệp được tạo bởi dao găm và dữ liệu. Nếu tôi xóa realm.io thì ứng dụng sẽ biên dịch chính xác.Realm.io/Dagger/Databinding trong cùng một dự án

Đây là build.gradle tôi

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

tôi thấy Realm cũng được tạo ra tập tin và có thể là trình biên dịch không chơi đẹp với nhau. Bất kỳ ý tưởng về làm thế nào để có được điều này làm việc?

Cảm ơn

+1

Vâng, xử lý chú thích Realm được tạo lớp proxy cũng được biên soạn trong một xây dựng. Trong ảnh chụp màn hình có vẻ như các lỗi liên quan đến các lớp khác ngoài Realm. Ứng dụng của bạn có được tạo nếu bạn loại bỏ lĩnh vực không? – geisshirt

+0

Vâng, tôi loại bỏ lĩnh vực ứng dụng xây dựng tốt – Darussian

+0

hey là nó giải quyết – Ajinkya

Trả lời

1

Realm, Dagger2 và Databinding đều đang làm việc trong dự án của tôi.

Sự khác biệt là:

Tôi đang sử dụng plugin gradle android 1.5.0 và bật dữ liệu theo cấu hình sau.

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

Và tôi không có

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

trong phụ thuộc.

dự án làm việc Tổng số là ở đây: https://github.com/zaki50/realm_template

+0

Sau khi cập nhật plugin gradle android 2.0.0 và lĩnh vực để 0.88.3, ​​bạn có thể xây dựng thành công? – codezjx

2

Tôi thấy rằng bạn cũng nhận được lỗi:

No setter found for field goalInfo

Hãy chắc chắn rằng các tên trường cũng giống như các getter và setter. Đừng thêm "m" vào tên trường. Ví dụ:

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

    public String getGoalInfo() { 
     return goalInfo; 
    } 

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

Giờ đây, bạn có thể triển khai giao diện RealmModel và thêm chú thích @RealmClass vào lớp thay vì mở rộng RealmObject. Điều này cho phép bạn mở rộng BaseObservable tuy nhiên nó vẫn không hoạt động.

Bạn nhận được một lỗi liên kết dữ liệu: gói mypackage.databinding không tồn tại

Xem vấn đề này trên github: https://github.com/realm/realm-java/issues/2716

2

Databinding works with RealmObjects, nhưng bạn phải thực hiện quan sát được.

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); 
     } 
    } 
} 

Và Dagger + Databinding có thể phá vỡ lẫn nhau, mà bạn cần phải thêm

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

Không hoạt động. Nó cho thấy cùng một lỗi Gói không tồn tại –

+0

@LuvnishMonga có thể có nghĩa là bạn có một số lỗi trong mã của bạn ở đâu đó – EpicPandaForce

+0

Mã đang hoạt động tốt.Tôi chỉ sử dụng Databinding và Realm. Khi lớp mô hình của tôi mở rộng sang RealmObject thì nó sẽ hiển thị lỗi giống với lỗi @Darussian đang gặp phải. Khi tôi thực hiện mã của bạn thì nó cho tôi thấy lỗi tương tự. –

Các vấn đề liên quan