I had a problem that I ask in kotlin-dsl issues here. I just copy it here.
Try to convert build.gradle
file of an Android library module to build.gradle.kts
failed with the following error:
Could not determine the dependencies of task ':app:testDebugUnitTest'.
> Could not resolve all task dependencies for configuration ':app:debugUnitTestRuntimeClasspath'.
> Could not resolve project :lib.
Required by:
project :app
> Cannot choose between the following variants of project :lib:
- debugAndroidTestCompile
- debugAndroidTestCompileOnly
- debugAndroidTestRuntime
- debugRuntime
- debugUnitTestCompile
- debugUnitTestCompileOnly
- debugUnitTestRuntime
- releaseRuntime
- releaseUnitTestCompile
- releaseUnitTestCompileOnly
- releaseUnitTestRuntime
All of them match the consumer attributes:
- Variant 'debugAndroidTestCompile':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugAndroidTestCompileOnly':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugAndroidTestRuntime':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugRuntime':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugUnitTestCompile':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugUnitTestCompileOnly':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'debugUnitTestRuntime':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'releaseRuntime':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'releaseUnitTestCompile':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'releaseUnitTestCompileOnly':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'releaseUnitTestRuntime':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Found org.jetbrains.kotlin.localToProject ':lib' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
You can see the error is happened in this commit of LiveEvent’s Android library while running ./gradlew clean check
.
Expected Behavior
Configure an Android library as before.
Current Behavior
After migrating to Kotlin DSL the implementation(project(":lib"))
of an Android app module cannot find the correct configuration of the library module. Also implementation(project(":lib", configuration = "default"))
generates the following error
e: LiveEvent/app/src/main/java/com/hadilq/liveevent/sample/LiveEventViewModel.kt: (20, 29): Unresolved reference: LiveEvent
e: LiveEvent/app/src/main/java/com/hadilq/liveevent/sample/LiveEventViewModel.kt: (23, 32): Unresolved reference: LiveEvent
Steps to Reproduce (for bugs)
Checkout to this commit of LiveEvent’s Android library, then running ./gradlew clean check
.
Your Environment
$ uname -a
Linux localhost.localdomain 4.20.8-100.fc28.x86_64 #1 SMP Wed Feb 13 13:09:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux