-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class keys into map don't work in Kotlin 1.3.30 #1478
Comments
The issue probably comes from Kotlin as it is the Kotlin update that stopped the code for working. |
Can't update Kotlin version yet because of the following issue: google/dagger#1478
* Bump deps versions Can't update Kotlin version yet because of the following issue: google/dagger#1478 * Move Resource to shared model package * Call dashboardViewModel.save() in onPause When it was called in onStop, sometimes, the dashboard wasn't saved.
Would you mind expanding on the workaround with an example? |
@VeegaP You switch the /**
* Workaround in Java due to Dagger/Kotlin not playing well together as of now
* https://github.com/google/dagger/issues/1478
*/
@MapKey
@Documented
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ViewModelKey {
Class<? extends ViewModel> value();
} |
Thank you @bleeding182 :) |
Should be fixed in kotlin 1.3.31 (yet to be released) according to the kotlin issue linked above |
I still have the same issue. @bleeding182 Workaround doesn't work for me. |
@vladkarpman post your error and your exact workaround code |
Setup: I am using workaround which was suggested @bleeding182.
This is my
Below is my
And this is error which i am facing:
|
@vladkarpman list of things you need to check:
|
@mikehc i checked everything from provided list, still the same error :( |
@vladkarpman post the rest of the other files, including imports. Maybe someone else has a better idea. |
@vladkarpman switch back to the old Kotlin version until this gets fixed. Which imports are you using in the factory class? |
@DDihanov added imports inside |
@vladkarpman Yup everything is fine on your end. I don't know why it keeps crashing. I "fixed" this issue by downgrading to |
@DDihanov something went totally wrong, now if i even downgrade Kotling version, i still have this issue. Before everything just worked. Of course, I tried to clean project. |
Sometimes a build cache of kapt doesn't track deleted kotlin files. Probably you have to not only clean build dir but delete build cache as well. |
Please try to run ./gradlew cleanBuildCache in your project, then remove your build folder, then try again. |
I can confirm, downgrading Kotlin fixes this.. |
I reset my branch to previous commit and investigated a bit more and found out that cause of my issue was gradle version 5.1.1 in mix with latest Kotlin version. So, robust solution to this issue is following:
Will wait for Koltin&Gradle fixes :) |
This is now fixed in kotlin 1.3.31 https://github.com/JetBrains/kotlin/blob/1.3.30/ChangeLog.md |
I'm having the same issue on
|
same |
same |
same in kotlin 1.3.50 |
Facing this with 1.3.41 , will check with latest - x.50 and x.60 and see if it resolves |
@aldefy Same issue in x.50, x.60 and x.61 |
what are you guys trying at the moment ? |
1.3.70 same issue |
1.3.71 same 🤔 |
Still happening with 1.3.71 Changing to java doesn't work. Why is this issue closed, it doesn't seem to be resolved yet |
To anyone still complaining, care to provide a sample repro project? Thank you. |
I can confirm the Java workaround [1] works fine with [1] #1478 (comment) |
I clear my gradle cache and rerun and the java solution is working now |
I tried all of these and none of the above worked for me dagger_version = ‘2.27' |
#1540 |
Tried the solutions provided in this thread, yet facing the same issue. dagger = 2.15 |
Still facing the issue. Anyone found any solution ? |
Setup:
Error:
Current state:
Injecting a
Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
based onKClass<out ViewModel
keys produces an error.Changing to
Map<KClass
... doesn't help.Expected state:
Injecting a
Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
based onKClass<out ViewModel
keys should work as before.Workaround:
Migrate the class key annotation to Java.
Relevant code:
Sample
DaggerKotlin.zip
The text was updated successfully, but these errors were encountered: