java - 将 Android Studio 升级到 4.0 后,我得到 'Caused by: java.lang.IllegalStateException: Unexpected non-class file'

标签 java android android-studio

当我尝试使用 Android Studio 4.0 运行仪器测试时,我得到

Caused by: java.lang.IllegalStateException: Unexpected non-class file: META-INF\versions\9\org\junit\platform\commons\util\ModuleUtils$ModuleReferenceScanner.class
直到我将 Android Studio 从 3.x 升级到 4.0 才发生这种情况。
有人解决了吗?提前致谢。

最佳答案

这是我想出的解决问题的技巧……我认为不需要这些类文件,删除它们似乎不会造成任何问题。

/**
 * Hack to work around this problem: https://stackoverflow.com/q/62540396
 * I don't think we use these class files at all so we can just delete them before dexing. I tried to see if we could
 * configure the file collection to exclude them instead, but it's actually just a collection of folders, which
 * internally the task just traverses separately.
 */
allprojects {
    tasks.withType<DexArchiveBuilderTask> {
        doFirst {
            mixedScopeClasses
                .asFileTree
                .matching { include("**/META-INF/versions/9/**/*.class") }
                .forEach { it.delete() }
        }
    }
}
(这是 Kotlin - 如果你使用 Groovy 会略有不同)

关于java - 将 Android Studio 升级到 4.0 后,我得到 'Caused by: java.lang.IllegalStateException: Unexpected non-class file',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62540396/

相关文章:

java - 嵌入多对一关系的属性

java - 如何接受 byte[] 作为对 POST 的响应

java - 切换表格列以输入数据

android - 从 GridView 中的特定 SDCard 文件夹加载图像

iphone - 如何使用 UDID 或设备 token 进行安全登录?

facebook - 在 Android 中发布 facebook sdk 4.0 时访问 token 被删除

java - 严重 : A child container failed during start java. util.concurrent.ExecutionException

android - ImageButton 使用 @android :drawable/programmatically 设置可绘制

eclipse - 调试Gradle 1.12依赖关系解决问题

intellij-idea - 如何修复 IntelliJ 14.1 中被截断的文本底部?