Android room persistent: AppDatabase_Impl does not exist

My app database class

@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:+"

And when i ask for instance it will give this error, AppDatabase_Impl does not exist in 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

    }   

}

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

for example:

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

also remember to add this plugin

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)

In Android Studio, if you get errors when you paste code or during the build process, select Build >Clean Project. Then select Build > Rebuild Project, and then build again.


UPDATE

If you have migrated to androidx

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

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

UPDATE 2 (since July 2021)

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

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

Just use

apply plugin: 'kotlin-kapt'

in app build.gradle

And keep both in dependencies

annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
kapt "android.arch.persistence.room:compiler:$rootProject.roomVersion"

EDIT

In newer version don't need to add both dependencies at a time Just use, hope it will work.

kapt 'android.arch.persistence.room:compiler:1.1.1'

I had this error when I missed

@Database(entity="{<model.class>})

Ensure that the entity model specified in the annotation above refers to the particular model class and also ensure that the necessary annotation:

@Entity(tableName = "<table_name>" ...)

is properly defined and you'd be good


if you are using kotlin classes to implement database then use

apply plugin: 'kotlin-kapt'

and

kapt "android.arch.persistence.room:compiler:1.1.1"

in your gradle file, it will work.


For Kotlin Developers

Use this:

implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"

And add apply plugin: 'kotlin-kapt' to the top of the app level build.gradle.

For Java Developers

implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"