8000 Cannot use new compiler with dagger.hilt.android.plugin · Issue #2086 · google/dagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Cannot use new compiler with dagger.hilt.android.plugin #2086

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

Closed
lukas1 opened this issue Sep 10, 2020 · 14 comments · Fixed by #2087
Closed

Cannot use new compiler with dagger.hilt.android.plugin #2086

lukas1 opened this issue Sep 10, 2020 · 14 comments · Fixed by #2087

Comments

@lukas1
Copy link
lukas1 commented Sep 10, 2020

Version: 2.29

As per release notes of Dagger 2.29 (https://github.com/google/dagger/releases/tag/dagger-2.29)

I've tried to change the compiler dependency to:

kapt "com.google.dagger:hilt-compiler:2.29-alpha"

This however doesn't work, if I have applied dagger.hilt.android.plugin. It says:

The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android-compiler dependency was found.
@bcorso
Copy link
bcorso commented Sep 10, 2020

Thanks! We can send out a patch for that soon.

In the mean time, you can continue using com.google.dagger:hilt-android-compiler. The new hilt-compiler artifact is just a rename.

copybara-service bot pushed a commit that referenced this issue Sep 10, 2020
Update the dependency check the Hilt Gradle Plguin does to consider the
new coordinates of the Hilt compiler.

Fixes: #2086
RELNOTES=Update Hilt Gradle Plugin to recognize hilt-compiler artifact.
PiperOrigin-RevId: 330939237
@bcorso
Copy link
bcorso commented Sep 10, 2020

Update: 2.29.1 should now be available with the fix.

@ThanosFisherman
Copy link

Still having this issue on a multi-module android project with android gradle plugin 4.1.0

@bcorso
Copy link
bcorso commented Oct 13, 2020

Hi @ThanosFisherman,

Can you check that you are using version com.google.dagger:hilt-android-gradle-plugin:2.29.1-alpha of the plugin?

Also check the error message for the failing Gradle module and verify that you've added the Hilt dependencies to that Gradle module. Note: You may need to go to the raw error message to find the failing Gradle module, as shown below:

image

If none of that helps, we would need a sample project or more explicit steps to reproduce the problem.

@ThanosFisherman
Copy link

Hi @bcorso,

Thanks for pointing me to the right direction. Upon second look I realized that I had some unwanted lines in my gradle scripts that would consequently cause hilt to throw this error. After deleting those lines everything builds without errors, but now I do get runtime errors that I wouldn't get with hilt 2.28-alpha

java.lang.InstantiationException: java.lang.Class<AuthViewModel> has no zero argument constructor

But I suppose the error above is unrelated with this issue.

I'm also confused with the number of dependencies I should include as of the new hilt 2.29.1 Could you please verify that everything I included is correct?

I use hilt gradle plugin in my root gradle build file

com.google.dagger:hilt-android-gradle-plugin:2.29.1-alpha

then in my app level gradle file I added the following

kapt("com.google.dagger:hilt-compiler:2.29.1")
and
implementation("com.google.dagger:hilt-android:2.29.1")
also for viewmodel I use
implementation("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02")
and lastly I add the plugin id like so id("dagger.hilt.android.plugin")

And that's all. I did not included the hilt-core dependency whatsoever

@lukas1
Copy link
Author
lukas1 commented Oct 14, 2020

@ThanosFisherman

java.lang.InstantiationException: java.lang.Class has no zero argument constructor

Sounds like you maybe did not use @ViewModelInject for the constructor of your AuthViewModel...

something like this

class AuthViewModel @ViewModelInject constructor(
  private val someDependency: SomeType
) : ViewModel() {}

You're saying you included this:
implementation("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02")

You actually need this dependency to enable that @ViewModelInject annotation. You wouldn't need that package if you wouldn't use that annotation. But in your case, you do need that package and you do need to use that annotation.

A few weeks ago I wrote a TLDR article with minimum setup of Dagger Hilt necessary, might be helpful to you to understand which dependencies you need to add:
https://medium.com/@vyletel/dagger-hilt-tldr-aa4fa361bf84

@ThanosFisherman
Copy link
ThanosFisherman commented Oct 14, 2020

I'm already using @ViewModelInject in my ViewModels I did not have any problems with 2.28-alpha

Maybe I am missing something. I'll have a look at your article and if I still can't figure out what's causing this runtime crash, I'll create a sample project that reproduces this issue and post back. Probably I will open a new ticket as well.

Thanks

@mochadwi
Copy link

I'm also occurred this problem when migrating to hilt-compiler and shows the same error message

Does it needs to invalidate caches & restart first? *or deleting gradle/caches

@ThanosFisherman
Copy link

@mochadwi have a look at this #2147 maybe you are missing something in your dependencies like I did

@mochadwi
Copy link
mochadwi commented Oct 21, 2020

Agreed. After updating, add missing hilt dependency, invalidating, cleaning & rebuilding it works in my case.

@abcbitlab123
Copy link
abcbitlab123 commented Jan 27, 2021

Maybe , You didn,t have """ classpath "com.google.dagger:hilt-android-gradle-plugin:2.30.1-alpha""" in your dependencies

@Drjacky
Copy link
Drjacky commented Jun 1, 2021

@bcorso Could you please take a look into #2661

@diegoflassa
Copy link

O solved mine by adding the following dependencies

// Dagger & Hilt
implementation("com.google.dagger:hilt-android:2.40")
kapt("com.google.dagger:hilt-android-compiler:2.40")
implementation("androidx.hilt:hilt-common:1.0.0")
kapt("androidx.hilt:hilt-compiler:1.0.0")
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
implementation("androidx.hilt:hilt-work:1.0.0")

@kavatari
Copy link

@diegoflassa thanks, the only one thing that helped me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
0