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

Import for <ERROR TYPE: MyResponse<List<AppObjectResponse>, Unit>> not found #682

Open
SomethingNice2016 opened this issue Oct 12, 2024 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@SomethingNice2016
Copy link

Ktorfit version

2.1.0

What happened and how can we reproduce this issue?

Hello. At the moment I have a problem. I have a cross-platform application on 2 platforms. I wrote my own wrapper for respons in generics, but at the compilation stage I get an error. The wrapper class is in another module. Please help me solve this problem
image

What did you expect to happen?

Happy code generation

Is there anything else we need to know about?

I am using this implementation in an android project. Everything works correctly in it

@SomethingNice2016 SomethingNice2016 added the bug Something isn't working label Oct 12, 2024
@Foso
Copy link
Owner

Foso commented Oct 12, 2024

Thank you for the report! I tried to reproduce it, but i was not able yet

@SomethingNice2016
Copy link
Author

Ktorfit does not generate implementations for all interfaces that are located in another module, even if they do not have generics

@SomethingNice2016
Copy link
Author

image
image

@Foso
Copy link
Owner

Foso commented Oct 15, 2024

Can you please try to reproduce it with the Multiplatform project https://github.com/Foso/Ktorfit/tree/master/example/MultiplatformExample . I want to find a fix for that bug, but when i use the classes everything is working fine. #634 seems to be the same issue

@Foso Foso added the help wanted Extra attention is needed label Oct 18, 2024
@Thijsiez
Copy link

Thijsiez commented Jan 6, 2025

Hej Jens,

I just started playing around with Ktorfit today, but I'm running into the same issue here.
My project's app is a Compose Multiplatform project (currently targeting Android and JVM), but the DTO models I want to use are located in a separate common module, which is also used by the server.

The project structure is like this

app
  androidApp
  desktopApp
  shared
common
server

The following is part of my server and app settings.gradle.kts, so I can reach the DTO models

include(":common")
project(":common").projectDir = file("../common")

And I then also define a dependency on the project, of course

implementation(project(":common"))

Now take my UserDto, say com.example.common.model.UserDto from the common module, which I want to use in the shared source set within the app project. That works fine, as long as I don't wrap the DTO in some container type when defining my interface.

For example, the following works fine:

@GET("users/current")
suspend fun currentUser(): UserDto

But the moment I change the return type of my function, I get the same errors as shared above. I've tried Flow<UserDto>, Call<UserDto>, and MyOwnVeryFancyWrapperClass<UserDto>, but they all fail in exactly the same way.
When I remove the wrapper, it immediately compiles and works fine again! So it probably has to do with resolving the generic type parameter, I guess?

Let me know if you could use any other information, or if I can be of assistance. I've been dabbling with KSP and KotlinPoet for the last few months. I'll see if I can find the time to maybe set up a test environment and do some root cause analysis :)

Kotlin 2.0.21 and Ktorfit 2.2.0 btw, only using ktorfit-lib-light, and the Gradle plugin of course

image

@Thijsiez
Copy link

Thijsiez commented Jan 7, 2025

The issue seems to be fixed by adding the main source dir of the external common module to commonMain. This is what I added to my app/shared/build.gradle.kts script:

kotlin {
    ...
    sourceSets {
        ...
        commonMain.configure {
            val dirs = kotlin.srcDirs.map { it.path }.toTypedArray()
            kotlin.srcDirs(*dirs, "../../common/src/main")
        }
        commonMain.dependencies {
            ...
            compileOnly(project(":common"))
            implementation(libs.bundles.ktorfit)
        }
        ...
    }
}

This isn't a pretty fix, but at least KSP can now resolve the classes we're trying to reference.
Hope this helps someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants