dlew / joda-time-android

Joda-Time library with Android specialization
Apache License 2.0
2.62k stars 183 forks source link

No matching variant of net.danlew:android.joda:2.10.14 was found. #303

Closed yoontaeseong closed 2 years ago

yoontaeseong commented 2 years ago

Summary

Using version 2.10.14, When using the library, the following error occurs only in buildTypes (Build Variant) staging. There is no error in release and debug

This issue does not occur in 2.10.7.2, but it seems to occur in the latest version 2.10.14.

Below is a summary of the error.

An error like this:

* What went wrong:
Execution failed for task ':app:hiltAggregateDepsDebug'.
> A failure occurred while executing dagger.hilt.android.plugin.task.AggregateDepsTask$WorkerAction
   > 'java.lang.String com.squareup.javapoet.ClassName.canonicalName()'

* Exception is:
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':presentation:dataBindingMergeDependencyArtifactsStaging'.
> Could not resolve all files for configuration ':presentation:stagingCompileClasspath'.
   > Could not resolve net.danlew:android.joda:2.10.14.
     Required by:
         project :presentation
      > No matching variant of net.danlew:android.joda:2.10.14 was found. The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'debugVariantMavenApiPublication' capability net.danlew:android.joda:2.10.14 declares an API of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'debugVariantMavenJavaDocPublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'debugVariantMavenRuntimePublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'debugVariantMavenSourcePublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'releaseVariantMavenApiPublication' capability net.danlew:android.joda:2.10.14 declares an API of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'releaseVariantMavenJavaDocPublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'releaseVariantMavenRuntimePublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'releaseVariantMavenSourcePublication' capability net.danlew:android.joda:2.10.14 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'staging'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')

Versions

My guess is that the library doesn't support the staging build variant. or Did I miss something?

dlew commented 2 years ago

It looks like you're trying to make the library build a staging variant, which isn't a standard Android thing (just something unique to your build).

Do you have a reproduction project I could take a look at?

yoontaeseong commented 2 years ago

There are some unpublishable codes, so I brought sample codes temporarily.

Below code is BuildTypes based on app/build.gradle


android {
    buildTypes {
            debug {
                signingConfig = signingConfigs.getByName("release")

                applicationIdSuffix = ".debug"
                ....
            }

            release {
                signingConfig = signingConfigs.getByName("release")

                proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
                proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")

                ...
            }
            create("staging") {
                signingConfig = signingConfigs.getByName("release")

                isMinifyEnabled = false
                isDebuggable = true
            }
            baseCommonBuildConfigField() //  just extension func
     }    
}

dependencies {

   ...

   implementation("net.danlew:android.joda:2.10.14")

   ...

}
dlew commented 2 years ago

I researched the issue and the problem is that your app includes a build type ("staging") that the library dependency (joda-time-android) does not have.

The solution is to use matchingFallbacks, as described here. Here's an example:

create("staging") {
  // ...your code...

  matchingFallbacks = ['debug', 'release']
}