CrimeDetailViewModelFactory fails with error "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option"

On page 282 CrimeDetailViewModelFactory failed with error
Inheritance from an interface with ‘@JvmDefault’ members is only allowed with -Xjvm-default option”.

I followed the definition of the Factory interface and couldn’t find any @JvmDefault annotation so I don’t quite understand why this error occured.

The solution I found here was to add

...

android {
    ...

    kotlinOptions {
        ...

        freeCompilerArgs +="-Xjvm-default=all"
    }

    ...
}

...

in the app build.gradle file.

1 Like