本文介绍了Android room persistent:AppDatabase_Impl不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用数据库类

@Database(entities = {Detail.class}, version = Constant.DATABASE_VERSION)
public abstract class AppDatabase extends RoomDatabase {

private static AppDatabase INSTANCE;

public abstract FavoritesDao favoritesDao();

public static AppDatabase getAppDatabase(Context context) {
    if (INSTANCE == null) {
        INSTANCE =
                Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, Constant.DATABASE).allowMainThreadQueries().build();

                //Room.inMemoryDatabaseBuilder(context.getApplicationContext(),AppDatabase.class).allowMainThreadQueries().build();
    }
    return INSTANCE;
}

public static void destroyInstance() {
    INSTANCE = null;
}

}

Gradle lib:

编译android.arch.persistence.room:runtime:+


annotationProcessorandroid.arch.persistence.room:compiler:+

Gradle lib:
compile "android.arch.persistence.room:runtime:+"
annotationProcessor "android.arch.persistence.room:compiler:+"

当我要求提供此错误时,AppDatabase_Impl在我的应用程序类中不存在


And when i ask for instance it will give this error, AppDatabase_Impl does not existin my application class

public class APp extends Application {

private boolean appRunning = false;



@Override
public void onCreate() {
    super.onCreate();
    AppDatabase.getAppDatabase(this); //--AppDatabase_Impl does not exist

}

}

推荐答案

对于那些使用 Kotlin 的人,请尝试更改 annotationProcessor kapt 在应用 build.gradle

For those working with Kotlin, try changing annotationProcessor to kapt in the apps build.gradle

例如:

// Extensions = ViewModel + LiveData
implementation "android.arch.lifecycle:extensions:1.1.0"
kapt "android.arch.lifecycle:compiler:1.1.0"
// Room
implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"

还记得将apply plugin:'kotlin-kapt'添加到应用程序级build.gradle文件的顶部并执行清理和重建(根据)

also remember to add apply plugin: 'kotlin-kapt' to the top of the app level build.gradle file and do a clean and rebuild (according to https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#6)

这篇关于Android room persistent:AppDatabase_Impl不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 12:06