Kotlin with Room and Dagger - 编译错误

Shi*_*ppy 3 android kotlin dagger android-room

我正在处理我的第一个Android kotlin应用程序.我的第一个活动是使用模拟数据,我现在正在尝试从数据库中获取数据,但代码将无法编译.

Kotlin代码:

@Dao
interface TagGroupDao {

    @Query("select * from TagGroup")
    fun getAll(): LiveData<List<TagGroup>>
}
Run Code Online (Sandbox Code Playgroud)

这已经生成了这个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();
  }
}
Run Code Online (Sandbox Code Playgroud)

对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
Run Code Online (Sandbox Code Playgroud)

最后,我的依赖项:

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"
}
Run Code Online (Sandbox Code Playgroud)

从我设法收集的关于ComputableLiveData的内容来看,它是一个不能直接使用的内部类.

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

我在其他地方引用了MutableLiveData <>而没有问题; 我的活动观察数据集和更新.

谁能指出我正确的方向?

Dmi*_*try 5

改变这种依赖:

implementation "android.arch.lifecycle:livedata-core:1.1.1"
Run Code Online (Sandbox Code Playgroud)

对此:

implementation "android.arch.lifecycle:livedata:1.1.1"
Run Code Online (Sandbox Code Playgroud)