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

Viewed 453

When I try to Run an Instrumentation test with Android Studio 4.0 I get

Caused by: java.lang.IllegalStateException: Unexpected non-class file: META-INF\versions\9\org\junit\platform\commons\util\ModuleUtils$ModuleReferenceScanner.class

It did not happen until I upgraded Android Studio from 3.x to 4.0.

Anyone solved it? Thanks in advance.

1 Answers

This is the hack I came up with to solve the problem... I don't think these class files are needed, and deleting them doesn't seem to cause any problems.

/**
 * 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() }
        }
    }
}

(This is Kotlin - if you use Groovy it will be slightly different)

Related