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



我很不明白。我只是想实现这里找到的Android房间教程。我一直收到这个错误:

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

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

我数据库:

@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次,但我不得不跳过一些自动驾驶仪,因为我只想卷曲成一个球

检查构建。gradle(模块级)文件,在我的情况下(我混合Java &Kotlin)我有两个

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

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

去掉我不需要的,就解决了我的问题。参考这个问题的公认答案尝试用android创建房间数据库,但不断得到依赖错误查看更多信息。

最新更新