I'm having a weird issue with importing a local li...
# gradle
h
I'm having a weird issue with importing a local library into my project. The directory structure is like so:
Copy code
| Projects
    | Library
    | Project
I'm attempting to import it in my
settings.gradle.kts
file like so:
Copy code
include(":shared", ":androidApp")
project(":Library").projectDir = file("../Library")
However when syncing I get the following error:
Project with path ':Library' could not be found.
If I
println
the absolute path it matches the directory I'm looking for. Can I ask what I'm doing wrong? Android Studio is installed as a standard package (using Linux), and shouldn't have any permission issues accessing the directory.
v
You try to configure the project
:Library
without having it included first. But, assuming you use that in multiple projects doing it like that is a biiiiig no-go anyway. Never ever ever ever ever include one project in multiple builds. Instead make
Library
an own standalone build with own settings script and then use composite build (
includeBuild
) to include the whole build.
h
Thank you for the help and advice!
If you don't mind another question, do I need to do anything different when importing objects from my library project, after using
includeBuild
? I ask since I can't access them from my main project folder.
v
Did you also change your dependency declaration? Did you read the composite build documentation at all?
h
Yes, I looked over the Dependency Substitution section and added that to my
includeProject
declaration:
Copy code
includeBuild("../Library") {
    dependencySubstitution {
        substitute(module("uk.co.harnick:Library")).using(project(":"))
    }
}
And in my build.gradle file's dependencies, I changed the declaration to this:
Copy code
implementation("uk.co.harnick:Library:1.0-SNAPSHOT")
I'm assuming I'm misunderstanding or have missed something.
It seems my issue was specific to Kotlin Multiplatform, it's been detailed with KTIJ-18903. I added the following line to my project's gradle.properties file and it all works great!
kotlin.mpp.import.enableKgpDependencyResolution=true
v
I would recommend to avoid manual dependency substitution wherever possible. If your build in
Library
is properly configured to publish an artifact with those coordinates, just the simple
includeBuild
is necessary and no dependency substitution. The dependency substitution is only necessary for strange edge cases, or misconfigured builds not under your control.
I added the following line to my project's gradle.properties file and it all works great!
👌
h
I would recommend to avoid manual dependency substitution wherever possible.
Tested it without and it worked fine. I just added that previously to be doubly sure it wasn't a configuration issue. Thank you so much for your time!
👌 1