Skip to content
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

Incremental build failures with 2.25.2 (new Kotlin qualifier annotations) #1659

Closed
GrahamBorland opened this issue Oct 30, 2019 · 7 comments · Fixed by #1688 or #1696
Closed

Incremental build failures with 2.25.2 (new Kotlin qualifier annotations) #1659

GrahamBorland opened this issue Oct 30, 2019 · 7 comments · Fixed by #1688 or #1696
Assignees

Comments

@GrahamBorland
Copy link

GrahamBorland commented Oct 30, 2019

Seeing this frequently with incremental builds since updating to 2.25.2. Works fine on a clean build.

/path/to/AppComponent.java:78: error: [Dagger/MissingBinding] android.net.Uri cannot be provided without an @Provides-annotated method.
public interface AppComponent extends AndroidInjector<App>{
       ^
      android.net.Uri is injected at
          ynab.app.web.WebViewActivity.serverUrl

Here's the relevant parts of the component (Java):

public interface AppComponent extends AndroidInjector<App>{

    // lots of other stuff

    @Component.Builder
    interface Builder {

        // lots of other stuff

        @BindsInstance Builder serverUrl(@Named("ServerUrl") Uri serverUrl);

    }
}

The error only happens since updating Dagger to 2.25.2 and changing the injection site to benefit from the new Kotlin support.

BEFORE - always worked fine

@Inject @field:Named("ServerUrl") internal lateinit var serverUrl: Uri

AFTER updating to 2.25.2 - regular incremental build failures

@Inject @Named("ServerUrl") internal lateinit var serverUrl: Uri

If I have misunderstood what's supposed to be possible with 646e033 then I look forward to being educated. :)

Dagger 2.25.2
Kotlin 1.3.50
Android Gradle Plugin 3.5.1

@danysantiago
Copy link
Member

Thanks for reporting this! We are aware of some cases where Dagger is still unable to find the qualifier annotation, meaning you have to fallback to @field:Named.

I was able to reproduce the issue in a small project with two gradle modules. App and Lib. Where Lib has the Kotlin class being member injected and App is where Dagger is setup with kapt. The issue is that Dagger is failing to find the synthetic method where property annotations are placed when the class being inspected is not from source, i.e. its already compiled.

We are still working on a fix but at the same time I filled a bug towards kapt with regards to the stub inconsistency: https://youtrack.jetbrains.com/issue/KT-34684

@GrahamBorland
Copy link
Author

@danysantiago Thanks! In my case the Kotlin injection target is in the same gradle module as the Dagger setup.

Dagger is failing to find the synthetic method where property annotations are placed when the class being inspected is not from source, i.e. its already compiled.

Would this also apply in the case of incremental compilation in the same gradle module, i.e. if my Kotlin injection target class has already been compiled in a previous build?

@danysantiago
Copy link
Member

Yes - It might be possible that this is also observed during incremental builds.

@GuilhE
Copy link

GuilhE commented Nov 6, 2019

@GrahamBorland why not switching from @Named to @Qualifier?

Example:

@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class ServerDateFormat

@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class CalendarPickerDateFormat


@Provides
@Singleton
@ServerDateFormat
fun provideServerDateFormat(): SimpleDateFormat {
   return SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault())
}

@Provides
@Singleton
@CalendarPickerDateFormat
fun provideCalendarPickerDateFormat(): SimpleDateFormat {
   return SimpleDateFormat("dd/MMM/yyyy", Locale.getDefault())
}

Not as a workaround but as an improvement.

@gildor
Copy link

gildor commented Nov 7, 2019

@GuilhE This issue reproducible and for @Named and for @Qualifier, so no difference.

as an improvement

It's improvement only if you do not use this dependency between modules, sometimes you just cannot access annotation without creating a separate module for it which is overkill in many cases

@GuilhE
Copy link

GuilhE commented Nov 7, 2019

@gildor thanks for sharing this knowledge, never had to use @Qualifiers between modules, only in the provider class and ViewModels/Classes.

@chrisjenx
Copy link

I just noticed this where we are running kapt on a library -> app module style setup.

cgdecker pushed a commit that referenced this issue Dec 6, 2019
Having qualifiers in the generated MemberInjectors helps the root
downstream processor read Kotlin property annotations that are lost
across compilations due to https://youtrack.jetbrains.com/issue/KT-34684
When Dagger is applied to all subprojects with @Inject fields or
constructors then this change fixes #1659.

RELNOTES=Workaround missing Kotlin qualifiers annotations across compilation units by propagating qualifiers along with MemberInjectors when Dagger processor is applied to upstream projects.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=283574407
cgdecker pushed a commit that referenced this issue Dec 6, 2019
Having qualifiers in the generated MemberInjectors helps the root
downstream processor read Kotlin property annotations that are lost
across compilations due to https://youtrack.jetbrains.com/issue/KT-34684
When Dagger is applied to all subprojects with @Inject fields or
constructors then this change fixes #1659.

RELNOTES=Workaround missing Kotlin qualifiers annotations across compilation units by propagating qualifiers along with MemberInjectors when Dagger processor is applied to upstream projects.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=283574407
kluever pushed a commit that referenced this issue Dec 16, 2019
*** Reason for rollback ***

Caused b/145946461

*** Original change description ***

Propagate qualifiers for field injections in MemberInjectors.

Having qualifiers in the generated MemberInjectors helps the root
downstream processor read Kotlin property annotations that are lost
across compilations due to https://youtrack.jetbrains.com/issue/KT-34684
When Dagger is applied to all subprojects with @Inject fields or
constructors then this change fixes #1659.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=284670569
kluever pushed a commit that referenced this issue Dec 16, 2019
*** Reason for rollback ***

Caused b/145946461

*** Original change description ***

Propagate qualifiers for field injections in MemberInjectors.

Having qualifiers in the generated MemberInjectors helps the root
downstream processor read Kotlin property annotations that are lost
across compilations due to https://youtrack.jetbrains.com/issue/KT-34684
When Dagger is applied to all subprojects with @Inject fields or
constructors then this change fixes #1659.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=284670569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants