Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Android Room 'Attempt to recreate a file for type [Dao_Impl]'

I am very much at a loss. I am simply trying to implement the Android Room tutorial found here. I keep receiving this error:

Execution failed for task ':app:compileDebugJavaWithJavac'.
> javax.annotation.processing.FilerException: Attempt to recreate a file for type com.example...dao.UserDao_Impl

Despite retrying the tutorial three times. If it helps:
My DAO:

@Dao
public interface UserDao {
    // LiveData<> respects app lifecycle
    @Query("SELECT * FROM user")
    LiveData<List<User>> getAll();

    @Query("SELECT * FROM user WHERE id IN (:userIds)")
    List<User> loadAllByIds(int[] userIds);

    @Query("SELECT * FROM user WHERE first_name LIKE :first AND " +
            "last_name LIKE :last LIMIT 1")
    User findByName(String first, String last);

    @Insert
    void insert(User planetEntity);

    @Insert
    void insertAll(User... users);

    @Delete
    void delete(User user);
}

My database:

@Database(entities = {User.class}, version = 1, exportSchema = false)
@TypeConverters({Converters.class})
public abstract class AppRoomDatabase extends RoomDatabase {
    private static final String DATABASE_NAME = "climbing_app_database";
    private static AppRoomDatabase INSTANCE;

    public abstract UserDao userDao();

    public static AppRoomDatabase getDatabase(final Context context) {
        if (INSTANCE == null) {
            synchronized (AppRoomDatabase.class) {
                if (INSTANCE == null) {
                    //Creates the DB here
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            AppRoomDatabase.class, DATABASE_NAME)
                            .fallbackToDestructiveMigration()
                            .addCallback(new AppRoomDatabase.Callback() {
                                @Override
                                public void onCreate(@NonNull SupportSQLiteDatabase db) {
                                    super.onCreate(db);

                                }
                            })
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}

Would really appreciate anyone able to tell me how much of a sausage I am being.

I tried to repeat the tutorial 3 times, but I have to be skipping something on autopilot because I just want to curl into a ball

like image 866
Alex Smith Avatar asked Oct 11 '25 12:10

Alex Smith


1 Answers

Check your build.gradle (module-level) file, in my case (I was mixing Java & Kotlin) I had both

annotationProcessor 'androidx.room:room-compiler:2.5.2'

and

ksp 'androidx.room:room-compiler:2.5.2'

Removing whichever I didn't need solved the problem for me. Refer to the accepted answer in this question Trying to create room database with android, but keep getting dependency error for more information.

like image 59
Joseph Sang Avatar answered Oct 14 '25 14:10

Joseph Sang