Issue
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 moduletestlib
: 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
Solution
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.
Answered By - huskygrad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.