I have already tried all the approaches proposed before, but:
Task :app:kaptDebugKotlin FAILED
C:\Users\[directory]di\AssistedInjectModule.java:9: error: @AssistedModule's @Module must not include AssistedInject_AssistedInjectModule if @InstallIn is used
public abstract interface AssistedInjectModule {
^[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
I did everything the same as the Google sunflower application
View Model:
class ExerciseDetailViewModel @AssistedInject constructor(
private val exercisesRepository: ExercisesRepository,
@Assisted private val exercise: Exercise)
: ViewModel() {
.......
@AssistedInject.Factory
interface AssistedFactory {
fun create(exercise: Exercise): ExerciseDetailViewModel
}
companion object {
fun provideFactory(
assistedFactory: AssistedFactory,
exercise: Exercise
): ViewModelProvider.Factory = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return assistedFactory.create(exercise) as T
}
}
}
In Fragment:
@Inject
lateinit var exerciseDetailViewModelFactory: ExerciseDetailViewModel.AssistedFactory
private val mViewModel: ExerciseDetailViewModel by viewModels {
ExerciseDetailViewModel.provideFactory(
exerciseDetailViewModelFactory,
args.Exercise
)
}
And:
@InstallIn(FragmentComponent::class)
@AssistedModule
@Module(includes = [AssistedInject_AssistedInjectModule::class])
// Needed until AssistedInject is incorporated into Dagger
interface AssistedInjectModule
Problem solved
Factory and AssistedInjectModule removed and made other versions of dependencies
com.squareup.inject:assisted-inject-annotations-dagger2:0.5.2
I have already tried all the approaches proposed before, but:
I did everything the same as the Google sunflower application
View Model:
In Fragment:
And:
Gradle: