Shippy
Shippy

Reputation: 75

Kotlin with Room and Dagger - compile error

I'm tackling my first android kotlin app. Having got my first activity working with mocked data, I'm now trying to fetch data from a database, but the code won't compile.

Kotlin code:

@Dao
interface TagGroupDao {

    @Query("select * from TagGroup")
    fun getAll(): LiveData<List<TagGroup>>
}

This has generated this java code:

public class TagGroupDao_Impl implements TagGroupDao {
  private final RoomDatabase __db;

  public TagGroupDao_Impl(RoomDatabase __db) {
    this.__db = __db;
  }

  @Override
  public LiveData<List<TagGroup>> getAll() {
    final String _sql = "select * from TagGroup";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    return new ComputableLiveData<List<TagGroup>>() {
      private Observer _observer;

      @Override
      protected List<TagGroup> compute() {
        if (_observer == null) {
          _observer = new Observer("TagGroup") {
            @Override
            public void onInvalidated(@NonNull Set<String> tables) {
              invalidate();
            }
          };
          __db.getInvalidationTracker().addWeakObserver(_observer);
        }
        final Cursor _cursor = __db.query(_statement);
        try {
          final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("Id");
          final int _cursorIndexOfName = _cursor.getColumnIndexOrThrow("Name");
          final List<TagGroup> _result = new ArrayList<TagGroup>(_cursor.getCount());
          while(_cursor.moveToNext()) {
            final TagGroup _item;
            final long _tmpId;
            _tmpId = _cursor.getLong(_cursorIndexOfId);
            final String _tmpName;
            _tmpName = _cursor.getString(_cursorIndexOfName);
            _item = new TagGroup(_tmpId,_tmpName);
            _result.add(_item);
          }
          return _result;
        } finally {
          _cursor.close();
        }
      }

      @Override
      protected void finalize() {
        _statement.release();
      }
    }.getLiveData();
  }
}

The references to ComputableLiveData aren't resolving.

e: TagGroupDao_Impl.java:3: error: cannot find symbol
e: 

e: import android.arch.lifecycle.ComputableLiveData;
e:                              ^
e:   symbol:   class ComputableLiveData
e:   location: package android.arch.lifecycle
e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

Lastly, my dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    implementation "android.arch.persistence.room:runtime:1.0.0"
    implementation "android.arch.lifecycle:viewmodel:1.1.1"
    implementation "android.arch.lifecycle:livedata-core:1.1.1"
    implementation "android.arch.lifecycle:common-java8:1.0.0"
    implementation 'com.google.dagger:dagger:2.13'
    implementation "com.google.dagger:dagger:2.13"
    implementation "com.google.dagger:dagger-android:2.13"
    implementation "com.google.dagger:dagger-android-support:2.13"
    kapt "android.arch.persistence.room:compiler:1.0.0"
    kapt 'com.google.dagger:dagger-compiler:2.13'
    kapt "com.google.dagger:dagger-android-processor:2.13"
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    testImplementation 'junit:junit:4.12'
    testImplementation "android.arch.persistence.room:testing:1.0.0"
    testImplementation "android.arch.core:core-testing:1.1.1"
}

From what I've managed to glean about ComputableLiveData, it's an internal class not to be directly used.

If I remove the LiveData<> wrapper from the kotlin code, it compiles.

I've referenced MutableLiveData<> elsewhere without issue; my activity observes the dataset and updates.

Can anyone point me in the right direction?

Upvotes: 3

Views: 933

Answers (1)

Dmitry
Dmitry

Reputation: 2546

Change this dependency:

implementation "android.arch.lifecycle:livedata-core:1.1.1"

To this:

implementation "android.arch.lifecycle:livedata:1.1.1"

Upvotes: 5

Related Questions