持续的Android会议室: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:

 compile "android.arch.persistence.room:runtime:+"   

annotationProcessor "android.arch.persistence.room:compiler:+"

当我问例如它将给出此错误时,AppDatabase_Impl在我的应用程序类中不存在

public class APp extends Application {

private boolean appRunning = false;

@Override

public void onCreate() {

super.onCreate();

AppDatabase.getAppDatabase(this); //--AppDatabase_Impl does not exist

}

}

回答:

对于那些使用 ,请尝试在应用中更改annotationProcessorkapt``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文件的顶部,然后进行清理和重建(根据https://codelabs.developers.google.com/codelabs/android-

room-with-a-

view/#6进行)

Android Studio中,如果在粘贴代码时或在构建过程中出现错误,请选择Build> Clean Project。然后选择Build>

Rebuild Project,然后再次进行构建。


更新

如果您已迁移到androidx

def room_version = "2.2.3" // check latest version from docs

implementation "androidx.room:room-runtime:$room_version"

kapt "androidx.room:room-compiler:$room_version"

以上是 持续的Android会议室:AppDatabase_Impl不存在 的全部内容, 来源链接: utcz.com/qa/422279.html

回到顶部