我已经从 app
中分离了一个功能。模块转换为动态功能模块(名为 dfm
)。
该模块在我遵循所有最佳实践和要求的情况下完美运行。但是 androidTest 中使用 AndroidJUnit4
的测试用例之一并且 Espresso 在构建任务时不起作用并且失败和中断:mergeLibDexDebugAndroidTest
.
该项目包括:
app
模块:主模块 testlib
: 图书馆模块包含几个用于单元测试的类(不被不运行的 espresso 测试用例使用)dfm
: 动态功能模块 Espresso 测试用例所在的位置没有具体的错误,但它只是给出以下错误
留言:
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.
我无法获取特定错误并了解它是否是 Gradle 文件或我的代码中的问题,因为有 没有编译错误任何地方。请帮助我理解错误。谢谢
最佳答案
在错误日志中,我们看到以下行:
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}.
因此,在研究了上述消息后,提示它与 testlib
相关。 ,我重新检查了dfm/build.gradle
其中包含 androidTestImplementation project(":testlib")
.由于目前没有对 androidTests
的依赖。来自 testlib
,这是不必要的,因此失败了。因此我删除了不必要的 androidTestImplementation project(":testlib")
这使得测试构建成功。
关于动态功能模块中的 androidTest espresso 测试用例无法构建/运行 - 任务 ':dfm:mergeLibDexDebugAndroidTest' 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62926219/