簡體   English   中英

將 Android Studio 升級到 4.0 后,我得到“原因:java.lang.IllegalStateException:意外的非類文件”

[英]After upgrading Android Studio to 4.0 I get 'Caused by: java.lang.IllegalStateException: Unexpected non-class file'

當我嘗試使用 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 之后才發生這種情況。

有人解決了嗎? 提前致謝。

這是我想出的解決問題的技巧……我認為不需要這些 class 文件,刪除它們似乎不會造成任何問題。

/**
 * 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 會略有不同)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM