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

Question: Struggling with project setup #17

Closed
StephanSchuster opened this issue Nov 6, 2021 · 6 comments
Closed

Question: Struggling with project setup #17

StephanSchuster opened this issue Nov 6, 2021 · 6 comments

Comments

@StephanSchuster
Copy link

StephanSchuster commented Nov 6, 2021

I would like to try your library since it looks really promising.
However, I am struggling with the very basics in terms of project setup.

build.gradle:

classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.5.31-1.0.0"

app/build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.devtools.ksp'

android {
    ...
}
kotlin {
    sourceSets {
        main {
            kotlin.srcDir("build/generated/ksp/debug/kotlin")
        }
        main {
            kotlin.srcDir("build/generated/ksp/release/kotlin")
        }
    }
}
dependencies {
   ...
    implementation 'io.github.raamcosta.compose-destinations:core:0.9.1-beta'
    ksp 'io.github.raamcosta.compose-destinations:ksp:0.9.1-beta'
}

No matter if I add sourceSets for only debug, only release or both (as above), whenever I switch the build variant, I get the following error:

e: ...\app\build\generated\ksp\debug\kotlin\com\ramcosta\composedestinations\CoreAnimationExtensions.kt: (15, 7): Redeclaration: DefaultAnimationParams

Without switching build variants I can build the project.

I assume the problem is on my side. Could you please elaborate on how to properly setup my project for debug and release? Anything (else) I am doing wrong?

Please let me know if you need more details about my setup.

@StephanSchuster
Copy link
Author

StephanSchuster commented Nov 6, 2021

Okay, the above is obviously stupid in terms of source sets.
This here seems to work. Is this correct?

app/build.gradle:

kotlin {
    sourceSets {
        debug {
            kotlin.srcDir("build/generated/ksp/debug/kotlin")
        }
        release {
            kotlin.srcDir("build/generated/ksp/release/kotlin")
        }
    }
}

@raamcosta
Copy link
Owner

raamcosta commented Nov 6, 2021

Is that working? To be honest I have not setup this for multiple variants. But this seems related with the KSP issue and not directly with this library.
Have you looked here?

I'd love to ear from you when you get this to work, it will help me understand this for the next time someone is struggling with the same thing.

@StephanSchuster
Copy link
Author

Upfront: I am using Groovy, not kts. I am neither a Gradle expert, nor do I now anything about KSP.

Yes it is working. Actually it is the only setup that I found working for me. But I don't know if this is good or if there are better ways. I would be happy if someone could confirm this.

Yes I had a look at the link you provided.
I wasn't able to transfer the answer from keyboardr to Groovy and my setup.
I tried the answer from Seoung transferred to Groovy without success. Same problem.

android {
    buildTypes {  // not working for me
        debug {
            sourceSets {
                main {
                    kotlin.srcDir("build/generated/ksp/debug/kotlin")
                }
            }
        }
        release {
           ...
            sourceSets {
                main {
                    kotlin.srcDir("build/generated/ksp/release/kotlin")
                }
            }
        }
    }
    ...
}

From my understanding and my tests I can tell the following:

  • when I build with build variant "debug" your code is generated under build/generated/ksp/**debug**/kotlin
  • when I build with build variant "release" your code is generated under build/generated/ksp/**release**/kotlin
  • with any other setup than the one I mentioned is working for me, I cannot get debug AND release to work
  • either because classes are not found for the build variant (because I did not yet build this variant)
  • or because I get the "Redeclaration" error mentioned above (because then both variants are built)

I think it is crucial that debug AND release is working and not just once.

In your readme you are mentioning under setup (3): "main" and ".../debug/..." which I think is wrong or rather only working as long as you only build the debug variant.
In fact I just tried to build your project with debug and release and got the same "Redeclaration" error. Try it yourself.

When I compare the stuff "you" generate under build/generated/ksp/**debug**/kotlin and build/generated/ksp/**release**/kotlin, everything is binary identical. As said, I know nothing about KSP and I don't know if you can/should influence this. But as both folders are identical, it might make sense to ALWAYS generate to e.g. "main" (???) and ALWAYS have this included in the source set independent of the build variant.

@raamcosta
Copy link
Owner

Thanks for the elaborate response 👍
I was actually trying myself and I observed the same behaviour you're describing.
I believe your solution appears to be exactly what we want. I'll update my README.md, thank you so much for this 🙂

As far as changing the location to be the same for debug and release, I'll investigate it further, but it seems to me that this is related with this issue that soon should be solved, hopefully. For now, it seems expected, as we see a similar approach done here

Once again, thanks so much for taking the time. If there is anything else I can help with, I'd be glad :)

@StephanSchuster
Copy link
Author

Glad this helped. I you prefer, you can close this issue. On the other hand it would be nice to keep it open until the root cause in KSP is fixed or to track your current status in terms of better solutions (e.g. same location for debug and release).

@raamcosta
Copy link
Owner

Closing this issue, since this shouldn't bother anyone now that I updated the Readme. Thank you!

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

No branches or pull requests

2 participants