Search code examples
javaandroidandroid-roomaccess-modifiers

Android Studio: "attempting to assign weaker access privileges" error on Room Database implementation


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.

What is going on here?


Solution

  • To fix this error for Jetpack Compose and Paging 3 you need to use only these libraries. The reason causing errors is that ktx and the runtime dependency clashes if their versions don't match. All the dependencies must have the same version

    //ROOM
    implementation "androidx.room:room-runtime:2.6.1"
    kapt "androidx.room:room-compiler:2.6.1"
    implementation "androidx.room:room-ktx:2.6.1"
    implementation "androidx.room:room-paging:2.6.1"
    
    // Paging 3.0
    implementation 'androidx.paging:paging-compose:1.0.0-alpha15'