0

I've separated a feature from app module into a Dynamic Feature Module (named dfm ).

The module works perfectly where I've followed all best practices and requirements. But one of the test cases in the androidTest which uses AndroidJUnit4 and Espresso does not work and fails and breaks while building at the task : mergeLibDexDebugAndroidTest. The project consists of:

  • app module : Main module
  • testlib : Library module consisting few classes used for unit tests (Not used by the espresso test case that doesn't run)
  • dfm : Dynamic Feature Module where the espresso test case lies
    There is no specific error but it just gives the following error message:
2020-07-15 20:40:42.705:INFO:oejs.ServerConnector:Daemon worker Thread 34: Stopped ServerConnector@eda0043{HTTP/1.1}{localhost:0}
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':dfm:**mergeLibDexDebugAndroidTest**'.
    > Could not resolve all files for configuration ':dfm:debugAndroidTestRuntimeClasspath'.
       > Failed to transform classes.jar (project :testlib) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-desugaring-v2=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=androidJvm}.
          > No variants of project :app match the consumer attributes:
              - Configuration ':app:debugRuntimeElements' variant android-navigation-json:
                  - Incompatible attribute:
                      - Required artifactType 'android-classes-jar' and found incompatible value 'android-navigation-json'.
                  - Other attributes:
                      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
                      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                      - Required dexing-enable-desugaring 'true' but no value provided.
                      - Required dexing-incremental-desugaring-v2 'false' but no value provided.
                      - Required dexing-is-debuggable 'true' but no value provided.
                      - Required dexing-min-sdk '21' but no value provided.
                      - Found org.gradle.usage 'java-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
              - Configuration ':app:debugRuntimeElements' variant android-packaged-dependencies:
                  - Incompatible attribute:
                      - Required artifactType 'android-classes-jar' and found incompatible value 'android-packaged-dependencies'.
                  - Other attributes:
                      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
                      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                      - Required dexing-enable-desugaring 'true' but no value provided.
                      - Required dexing-incremental-desugaring-v2 'false' but no value provided.
                      - Required dexing-is-debuggable 'true' but no value provided.
                      - Required dexing-min-sdk '21' but no value provided.
                      - Found org.gradle.usage 'java-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
              - Configuration ':app:debugRuntimeElements' variant apk:
                  - Incompatible attribute:
                      - Required artifactType 'android-classes-jar' and found incompatible value 'apk'.
                  - Other attributes:
                      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
                      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                      - Required dexing-enable-desugaring 'true' but no value provided.
                      - Required dexing-incremental-desugaring-v2 'false' but no value provided.
                      - Required dexing-is-debuggable 'true' but no value provided.
                      - Required dexing-min-sdk '21' but no value provided.
                      - Found org.gradle.usage 'java-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
              - Configuration ':app:debugRuntimeElements' variant bundle-apks:
                  - Incompatible attribute:
                      - Required artifactType 'android-classes-jar' and found incompatible value 'bundle-apks'.
                  - Other attributes:
                      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
                      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                      - Required dexing-enable-desugaring 'true' but no value provided.
                      - Required dexing-incremental-desugaring-v2 'false' but no value provided.
                      - Required dexing-is-debuggable 'true' but no value provided.
                      - Required dexing-min-sdk '21' but no value provided.
                      - Found org.gradle.usage 'java-runtime' but wasn't required.
                      - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required. 

I'm unable to get a specific error and understand if it's a problem in the Gradle files or my code, as there are no compilation errors anywhere. Kindly help me to understand the error. Thanks

huskygrad
  • 1,257
  • 1
  • 10
  • 21
  • There is a lot that could affect this. Which module depends on which other module? What plugins to you have applied to each module? What version of gradle and the android gradle plugin are you using? – yogurtearl Jul 17 '20 at 03:31
  • Thanks for going through the complex issue and commenting your concern. I understand that it sounds vague, sorry for not able to provide more details. However, I was able to fix the problem - added the answer below. Thanks @yogurtearl – huskygrad Jul 24 '20 at 01:07

1 Answers1

1

In the error log, we see the line:

Failed to transform classes.jar (project :testlib) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-desugaring-v2=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=androidJvm}.

So after researching about the above message with the hint that it's related to testlib, I rechecked the dfm/build.gradle which contained the androidTestImplementation project(":testlib"). Since currently there was no dependency for androidTests from testlib, this was unnecessary and hence was failing. Therefore I removed the unnecessary androidTestImplementation project(":testlib") which made the test build successfully.

huskygrad
  • 1,257
  • 1
  • 10
  • 21