Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 834
Memduh Yılmaz Avatar asked Nov 26 '25 04:11

Memduh Yılmaz


1 Answers

I got this error because I used

implementation 'androidx.work:work-runtime-ktx:2.8.0-rc01'

with

implementation 'androidx.room:room-runtime:2.4.3'
kapt 'androidx.room:room-compiler:2.4.3'

and library

androidx.work:work-runtime-ktx:2.8.0-rc01

is dependent on

androidx.room:room-common:2.5.0-rc01

so I finished with two same libraries but with different versions

androidx.room:room-common:2.5.0-rc01
androidx.room:room-common:2.4.3

after switching back to

androidx.work:work-runtime:2.7.1

error was gone.

like image 144
Zoran Avatar answered Nov 27 '25 18:11

Zoran