Code Monkey home page Code Monkey logo

Comments (5)

bcorso avatar bcorso commented on August 20, 2024

Hmm, I'm not able to reproduce this following the instructions in your README:

DaggerAndroidKspError-main bcorso$ ./gradlew  :app:assembleDebug

BUILD SUCCESSFUL in 1s


And the generated code looks fine:

package com.example.daggerandroid;

import dagger.internal.DaggerGenerated;
import dagger.internal.Factory;
import dagger.internal.Preconditions;
import dagger.internal.QualifierMetadata;
import dagger.internal.ScopeMetadata;
import javax.annotation.processing.Generated;

@ScopeMetadata
@QualifierMetadata
@DaggerGenerated
@Generated(
    value = "dagger.internal.codegen.ComponentProcessor",
    comments = "https://dagger.dev"
)
@SuppressWarnings({
    "unchecked",
    "rawtypes",
    "KotlinInternal",
    "KotlinInternalInJava"
})
public final class ExampleModule_ProvideString$app_debugFactory implements Factory<String> {
  private final ExampleModule module;

  public ExampleModule_ProvideString$app_debugFactory(ExampleModule module) {
    this.module = module;
  }

  @Override
  public String get() {
    return provideString$app_debug(module);
  }

  public static ExampleModule_ProvideString$app_debugFactory create(ExampleModule module) {
    return new ExampleModule_ProvideString$app_debugFactory(module);
  }

  public static String provideString$app_debug(ExampleModule instance) {
    return Preconditions.checkNotNullFromProvides(instance.provideString$app_debug());
  }
}

Do you have any special configuration for your KSP setup? I think when using internal the appended string is the JPMS module name and it looks like in your case KSP is using app.debug.ksp rather than app.debug.

from dagger.

wbonnefond avatar wbonnefond commented on August 20, 2024

You helped me resolve it. I had set kotlin.incremental.useClasspathSnapshot=false in my local gradle.properties file while trying out Anvil. Removing this solves the issue. That being said, I would expect the output to be the same regardless of this flag

from dagger.

bcorso avatar bcorso commented on August 20, 2024

Fwiw, the jvm method name is not something we control in Dagger, it's given to us by KSP's APIs so if you think it's not working correctly with your flag you could ask the KSP team.

from dagger.

wbonnefond avatar wbonnefond commented on August 20, 2024

@bcorso after removing this flag I ran into another issue related to internal methods when using KSP. Basically referencing a dagger Module in a @ContributesAndroidInjector() annotation in different gradle module will fail. I updated the reproducer project to reflect this.

I'm wondering if this is just a behavior change with KSP since it probably can't see internal methods across gradle modules because it's respecting kotlin method visibility. Please let me know if this is expected behavior or if I should open a different issue.

e: [ksp] ComponentProcessingStep was unable to process 'com.example.daggerandroid.ExampleModule_ContributeAppClass$app_debug.AppClassSubcomponent' because '<error>' could not be resolved.

Dependency trace:
    => element (CLASS): com.example.mylibrary.LibraryModule_ContributeLibraryClass$mylibrary_debug
    => annotation type: dagger.Module
    => annotation: @dagger.Module(includes={}, subcomponents={<error>})
    => annotation value (TYPE_ARRAY): subcomponents={<error>}
    => annotation value (TYPE): subcomponents=<error>

If type '<error>' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type '<error>' is on your classpath.
e: Error occurred in KSP, check log for detail

from dagger.

bcorso avatar bcorso commented on August 20, 2024

Yeah, that is a different issue so might be best to just file a separate bug and keep this one closed.

The latest issue your seeing seems to be a bug in KSP (or XProcessing) where it doesn't seem to be able to handle class names that contain $ when referenced from annotations. In this case it affects the class Dagger generates from the @ContributesAndroidInjector annotation:

@Generated
@Module(subcomponents = LibraryModule_ContributeLibraryClass$mylibrary_debug.LibraryClassSubcomponent.class)
public abstract class LibraryModule_ContributeLibraryClass$mylibrary_debug {
  ...
}

In particular, the LibraryModule_ContributeLibraryClass$mylibrary_debug.LibraryClassSubcomponent type within the annotation is showing up as error type, hence the error message you're seeing.

I can work on filing a bug to KSP, but in the meantime I think the best workaround is to just remove internal from your @ContributesAndroidInjector methods.

from dagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.