Использование сопрограмм Kotlin в тесте Android Instrumentation с ProGuard - PullRequest
0 голосов
/ 15 января 2019

Я хочу использовать сопрограммы Kotlin в моих тестах инструментов для приложения Android. Я не использую их в самом приложении. Я также запускаю ProGuard для приложения.

Я пытаюсь использовать их так:

@RunWith(AndroidJUnit4::class)
class TheTest {

    @Rule
    @JvmField
    val activityTestRule = ActivityTestRule(MyActivity::class.java)

    @Test
    fun test() {
        runBlocking {}
    }
}

Однако при запуске этого теста происходит сбой со следующей ошибкой:

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/coroutines/jvm/internal/SuspendLambda;
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(Unknown Source:11)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(Unknown Source:2)
at org.junit.internal.runners.model.ReflectiveCallable.run(Unknown Source:0)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(Unknown Source:5)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(Unknown Source:14)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(Unknown Source:2)
at org.junit.runners.ParentRunner$3.run(Unknown Source:6)
at org.junit.runners.ParentRunner$1.schedule(Unknown Source:0)
at org.junit.runners.ParentRunner.runChildren(Unknown Source:25)
at org.junit.runners.ParentRunner.access$000(Unknown Source:0)
at org.junit.runners.ParentRunner$2.evaluate(Unknown Source:4)
at org.junit.runners.ParentRunner.run(Unknown Source:13)
at org.junit.runners.Suite.runChild(Unknown Source:0)
at org.junit.runners.Suite.runChild(Unknown Source:2)
at org.junit.runners.ParentRunner$3.run(Unknown Source:6)
at org.junit.runners.ParentRunner$1.schedule(Unknown Source:0)
at org.junit.runners.ParentRunner.runChildren(Unknown Source:25)
at org.junit.runners.ParentRunner.access$000(Unknown Source:0)
at org.junit.runners.ParentRunner$2.evaluate(Unknown Source:4)
at org.junit.runners.ParentRunner.run(Unknown Source:13)
at org.junit.runner.JUnitCore.run(Unknown Source:25)
at org.junit.runner.JUnitCore.run(Unknown Source:4)
at android.support.test.internal.runner.TestExecutor.execute(Unknown Source:24)
at android.support.test.runner.AndroidJUnitRunner.onStart(Unknown Source:46)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.coroutines.jvm.internal.SuspendLambda" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.myapp.test-d-f4s4j7q8wpEZJZvy9h4A==/base.apk", zip file "/data/app/com.myapp.dev-7Gs6UezsUbiSCx7s3jZ6LQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.dev.test-d-f4s4j7q8wpEZJZvy9h4A==/lib/x86, /data/app/com.myapp.dev-7Gs6UezsUbiSCx7s3jZ6LQ==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 27 more

Я пытался использовать testProguardFile со следующим содержимым:

-ignorewarnings
-dontobfuscate
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames

Но, похоже, это не помогает.

...