gradle Java Android Room '尝试重新创建类型为[Dao_Impl]的文件'

eufgjt7s  于 2023-10-19  发布在  Java
关注(0)|答案(1)|浏览(141)

我很茫然。我只是想实现Android的房间教程发现here .我一直收到这个错误:

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

尽管重新尝试了三次教程。如果有帮助的话:
我的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);
}

我的数据库:

@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;
    }
}

如果有人能告诉我我有多像香肠,我会很感激的。
我试着重复教程3次,但我必须跳过自动驾驶仪的东西,因为我只是想 curl 成一个球

fzsnzjdm

fzsnzjdm1#

检查你的build.gradle(模块级)文件,在我的情况下(我混合了Java和Kotlin),我两者都有

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

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

删除任何我不需要的解决了我的问题。更多信息请参考此问题Trying to create room database with android, but keep getting dependency error中接受的答案。

相关问题