Task 'wrapper' not found in project ':mylib'

I’m trying to integrate a Kotlin Multiplatform library with an existing Android app. I’d like to drop both git repositories into a root directory and then include the library in the app using these small changes.

This is a patch file from two test projects I created with the Android Studio wizard. One was a KMM project and the other was an Android app that just has the built in login screen activity.

 .idea/gradle.xml                                              | 2 +-
 app/build.gradle                                              | 1 +
 .../java/com/example/myapp/data/LoginDataSource.kt     | 4 +++-
 settings.gradle                                               | 2 ++
 4 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 4e3844e..10c8697 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -10,9 +10,9 @@
             <option value="$PROJECT_DIR$" />
             <option value="$PROJECT_DIR$/app" />
+            <option value="$PROJECT_DIR$/../mylib/shared" />
-        <option name="resolveModulePerSourceSet" value="false" />
diff --git a/app/build.gradle b/app/build.gradle
index 4b52039..a383303 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -43,6 +43,7 @@ dependencies {
     implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
     implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
     implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
+    implementation project(path: ':mylib')
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
diff --git a/app/src/main/java/com/example/myapp/data/LoginDataSource.kt b/app/src/main/java/com/example/myapp/data/LoginDataSource.kt
index a5990c5..2010210 100644
--- a/app/src/main/java/com/example/myapp/data/LoginDataSource.kt
+++ b/app/src/main/java/com/example/myapp/data/LoginDataSource.kt
@@ -1,5 +1,6 @@
 package com.example.myapp.data
+import com.example.mylib.Greeting
 import com.example.myapp.data.model.LoggedInUser
 import java.io.IOException
@@ -11,7 +12,8 @@ class LoginDataSource {
     fun login(username: String, password: String): Result<LoggedInUser> {
         try {
             // TODO: handle loggedInUser authentication
-            val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), "Jane Doe")
+//            val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), "Jane Doe")
+            val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), Greeting().greeting())
             return Result.Success(fakeUser)
         } catch (e: Throwable) {
             return Result.Error(IOException("Error logging in", e))
diff --git a/settings.gradle b/settings.gradle
index 3e6c77c..5a702f5 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -14,3 +14,5 @@ dependencyResolutionManagement {
 rootProject.name = "myapp"
 include ':app'
+include ':mylib'
+project(':mylib').projectDir = new File('../mylib/shared')
\ No newline at end of file

This solution works well with the sample projects. However when I try it with the actual existing projects I get an error, “Task ‘wrapper’ not found in project ‘:mylib’”. I see this error when I try to sync the project with the gradle files. Building the KMM project works fine too.

I’ve read a lot of documentation, but I don’t see an issue since that task should be created automatically. I only get this error when I try build the existing app that includes the shared library of the KMM project.

Any ideas on what I should try to fix this issue?

You probably configure the wrapper task in ../mylib/shared/build.gradle.
The wrapper task is only created in root projects, but now you include that project as subproject in another build and thus the task cannot be found.

The solution is not to remove the wrapper configuration, it is just a symptom that clearly shows that you are doing majorly wrong. You should never include a project from one build into another build. Instead include the whole build using composite build feature: Composing builds

Thank you for your quick response. It was very helpful. Your link to “Composing builds” eventually led me to a solution. I feel that the documentation can be greatly enhanced to make such a cool feature more easy to understand and implement.

The things that stumped me where that I was using “include” instead of “includeBuild” in settings.gradle. The docs show examples of how to specify the projectDir when using include, but it doesn’t mention anything for includeBuild. All of the examples for includeBuild reference just the name of the project and the method itself takes a Java “Object”, which doesn’t really give a lot of insight into what type of valid input it accepts.

In case anybody else is looking to include a project within yours that has a separate git repo, use a block like this:

includeBuild(“…/mylib”) {
dependencySubstitution {

This assumes that you have both projects in one root directory. You can just include the relative path as the parameter to includeBuild.

Then add a dependency in build.gradle for your app.
implementation ‘com.example:mylib:0.1’

You will need to have the group and version defined in your library’s build.gradle file too.
group = “com.example”
version = “0.1”

This short article I found had a cool hack that I found helpful.

If your included build is properly set up, you usually do not need any manual dependency substitutions.