mononz
mononz

Reputation: 1705

Android packageName test with kotlin 'kotlin.jvm.internal.Intrinsics' error

I'm looking to get started with connected tests on an existing android java app using kotlin tests. The test passed using the base provided ExampleInstrumentedTest.java but converting it to kotlin gave the following error.

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at com.tipple.ExampleInstrumentedTest.useAppContext(ExampleInstrumentedTest.kt:16)
at java.lang.reflect.Method.invoke(Native Method)
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.internal.Intrinsics" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.tipple.beta.test-vymqCjsywOdabXWVc-hoqA==/base.apk", zip file "/data/app/com.example.app-0snLmU24VolpPE8BTUvpfg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.app.test-vymqCjsywOdabXWVc-hoqA==/lib/arm64, /data/app/com.example.app-0snLmU24VolpPE8BTUvpfg==/lib/arm64, /data/app/com.example.app.test-vymqCjsywOdabXWVc-hoqA==/base.apk!/lib/arm64-v8a, /data/app/com.example.app-0snLmU24VolpPE8BTUvpfg==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]

Code used

package com.example.app

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Assert.assertEquals

import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {

    @Test
    fun useAppContext() {
        val appContext:Context = InstrumentationRegistry.getTargetContext()
        assertEquals("com.example.app", appContext.packageName)
    }
}

The above kotlin test worked in a new android project and I believe I have kotlin configured correctly in gradle as other kotlin tests are working fine. Seems to be just having a problem reading the packageName from the InstrumentationRegistry in this exising app.

Any ideas on what might be a cause?

NB: Am using proguard to fit app in a single dex.

Upvotes: 1

Views: 2473

Answers (1)

mononz
mononz

Reputation: 1705

Ah darn proguard again. I am minifying to fit in a single dex so I needed to make sure I kept the missing class in my proguard-rules-test.pro file

-keep kotlin.jvm.internal.Intrinsics

Working now, but I did need to have minifyEnabled false and multiDexEnabled true in my debug buildType.

Ideally I don't want to go multidex for devDebug builds as testing the app wouldn't be similar to production builds. Still looking for an alternative and likely to switch back to Java only tests.

Upvotes: 2

Related Questions