Skip to content

Android Studio Workarounds (1.0.32)

Marcel Schnelle edited this page Jul 28, 2018 · 1 revision

NOTE: This guide is archived, as it talks about outdated workarounds that are no longer necessary if you use the latest version of this plugin.

All versions up to Android Studio 3.1 Canary 6 are built on a version of IntelliJ IDEA that depends on outdated JUnit 5 APIs. Therefore, your tests will fail with an Exception similar to the following when you try to launch your tests from inside the IDE (using an Android JUnit Run Configuration):

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:42)
	...

To work around this, there is a separate dependency you can add to the test scope of your project in Android Studio 3. It provides its own copy of the JUnit 5 Runtime provided by a more recent build of IntelliJ, overriding the one embedded in Android Studio.

To use this, add the following line alongside the other junit5 dependencies:

dependencies {
  testCompileOnly junit5.unitTestsRuntime()
}

Starting with version 1.0.32 of the plugin, this dependency is deprecated. Please update to Android Studio 3.1 or later, and remove this extra dependency.

You can’t perform that action at this time.