티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Android room persistent: AppDatabase_Impl does not exist

안드로이드 룸 지속성: AppDatabase_Impl이(가) 존재하지 않습니다.

 문제 내용 

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:

Gradle 라이브러리:
 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

앱을 실행할 때 AppDatabase_Impl 클래스가 없다는 오류가 발생합니다. 이 오류는 앱의 Application 클래스에서 인스턴스를 요청할 때 발생합니다.
public class APp extends Application {

    private boolean appRunning = false;

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

    }   

}

 

 

 높은 점수를 받은 Solution 

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

Kotlin을 사용하는 경우, 앱의 build.gradle에서 annotationProcessor를 kapt로 변경해보세요.

 

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

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)

앱 수준의 build.gradle 파일 맨 위에 이 플러그인을 추가하고, Clean and Rebuild를 수행하세요. ([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.

안드로이드 스튜디오에서 코드를 붙여넣거나 빌드 과정 중 오류가 발생할 경우, Build > Clean Project를 선택한 다음 Build > Rebuild Project를 선택하여 다시 빌드하십시오.

 


UPDATE

업데이트:

 

If you have migrated to androidx

만약 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)

업데이트 2 (2021년 7월 이후)
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"

 

 

 가장 최근 달린 Solution 

Agreed with the above answers

위의 답변들과 동의합니다.

 

The solution is as below. Change annotationProcessor to kapt as below

해결책은 아래와 같습니다. 어노테이션 프로세서(annotationProcessor)를 다음과 같이 kapt로 변경하세요.
// annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

 

 

출처 : https://stackoverflow.com/questions/46665621/android-room-persistent-appdatabase-impl-does-not-exist

반응형
댓글
공지사항
최근에 올라온 글