Kotlin with Room and Dagger - 编译错误

Kotlin with Room and Dagger - compile error

我正在处理我的第一个 android kotlin 应用程序。我第一次 activity 使用模拟数据,现在我正尝试从数据库中获取数据,但代码无法编译。

Kotlin 代码:

@Dao
interface TagGroupDao {

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

这已生成此 java 代码:

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

未解析对 ComputableLiveData 的引用。

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

最后,我的依赖项:

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

根据我设法收集到的有关 ComputableLiveData 的信息,它是一个内部 class,不能直接使用。

如果我从 kotlin 代码中删除 LiveData<> 包装器,它会编译。

我在别处引用了 MutableLiveData<> 没有问题;我的 activity 观察数据集并更新。

谁能指出我正确的方向?

更改此依赖项:

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

为此:

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