Issue
I am trying to implement room database, I have gone through steps on Official Website, and 'AppDatabase.java' file is like this:
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
@Database(entities = {User.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public static AppDatabase instance;
public static synchronized AppDatabase getInstance(Context context){
if (instance==null){
instance = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class, "app_database").fallbackToDestructiveMigration().build();
}
return instance;
}
}
And dependencies I have used for room:
// Room Database
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - RxJava3 support for Room
implementation "androidx.room:room-rxjava3:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"
// optional - Paging 3 Integration
implementation "androidx.room:room-paging:2.5.0-alpha02"
// Room Database
It returns 2 errors here:
onCreate(SupportSQLiteDatabase) in <anonymous com.example.testdb1.room.AppDatabase_Impl$1> cannot override onCreate(SupportSQLiteDatabase) in Delegate
attempting to assign weaker access privileges; was public
onValidateSchema(SupportSQLiteDatabase) in <anonymous com.example.testdb1.room.AppDatabase_Impl$1> cannot override onValidateSchema(SupportSQLiteDatabase) in Delegate
attempting to assign weaker access privileges; was public
It was working before the 'Chipmunk' version (was working in 'Bumblebee'), but it started throwing these errors.
Can anyone tell me what is going on here?
Note: please if you are going to write code write where I put the code wisely, thanks.
Solution
To fix this error for Jetpack Compose and Paging 3 you only need to use only this libraries
//ROOM
implementation "androidx.room:room-runtime:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
implementation "androidx.room:room-paging:2.4.2"
// Paging 3.0
implementation 'androidx.paging:paging-compose:1.0.0-alpha15'
Answered By - Elizaveta Zalyaeva
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)