gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

Convert build.gradle file of an Android library module to build.gradle.kts failed #1356

Closed hadilq closed 5 years ago

hadilq commented 5 years ago

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

eskatos commented 5 years ago

Please use the Gradle forms for support questions https://discuss.gradle.org/

hadilq commented 5 years ago

Thank you @eskatos . Asked here

cassian237 commented 4 years ago

Ensure you use id("com.android.library") instead of id("com.android.application") for modules.

harshmittal29 commented 4 years ago

I am facing same problem as stated. Any solutions for it yet?