DatabaseManager_Impl不是抽象的,不会覆盖RoomDatabase中的抽象方法clearAllTables()

时间:2018-04-29 08:01:44

标签: java android kotlin

当我构建此代码时,它显示了构建错误:

  

DatabaseManager_Impl不是抽象的,不会覆盖抽象   RoomDatabase中的方法clearAllTables()。

的build.gradle:

implementation 'android.arch.persistence.room:runtime:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.persistence.room:rxjava2:1.0.0'
implementation 'android.arch.persistence.room:guava:1.1.0-beta3'

根据房间指南实施数据库:

@Database(entities = {Task.class}, version = 1)
public abstract class DatabaseManager extends RoomDatabase {
    private static final String DATABASE =
                         Iterables.getLast(Splitter.on(".").trimResults().split(BuildConfig.APPLICATION_ID)).concat("-db");
    private static volatile DatabaseManager instance;

    public abstract TaskDao taskDao();

    synchronized public static DatabaseManager onInstance(Context context)     {
        if (instance == null) {
            instance = newInstance(context, false);
        }
        return instance;
    }

    public static DatabaseManager newInstance(Context context, boolean memoryOnly) {
        RoomDatabase.Builder<DatabaseManager> builder;

        if (memoryOnly) {
            builder = Room.inMemoryDatabaseBuilder(context.getApplicationContext(), DatabaseManager.class);
        } else {
            builder = Room.databaseBuilder(context.getApplicationContext(), DatabaseManager.class, DATABASE);
        }

        return builder.fallbackToDestructiveMigration().build();
    }

}

2 个答案:

答案 0 :(得分:17)

我有同样的问题,并意识到

//room
    implementation "android.arch.persistence.room:runtime:${arch_version}"
    kapt "android.arch.persistence.room:compiler:${arch_version}"
    implementation "android.arch.persistence.room:rxjava2:${arch_version}"

这些依赖项应该具有相同的版本。它们都是1.0.0或1.1.0。不同的版本会导致问题。

答案 1 :(得分:1)

我的修复方法是将所有会议室版本的版本更改为1.0.0

另请务必使用kapt代替annotationProccessor