Saturday, 20 February 2021

AWS Device Farm - java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.AndroidJUnitRunner"

Good day! I'm trying to use AWS Device Farm for instrumented tests. But for SOME devices I got this error:

02-17 19:22:26.157 15281 15281 E AndroidRuntime: FATAL EXCEPTION: main
02-17 19:22:26.157 15281 15281 E AndroidRuntime: Process: com.mobilesense.myapplication, PID: 15281
02-17 19:22:26.157 15281 15281 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.mobilesense.myapplication.test/androidx.test.runner.AndroidJUnitRunner}: java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.AndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5956)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.app.ActivityThread.-wrap3(ActivityThread.java)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1727)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6823)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
02-17 19:22:26.157 15281 15281 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.AndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5954)
02-17 19:22:26.157 15281 15281 E AndroidRuntime:    ... 8 more

My app level gradle link:

...

android {
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.signalsense.signalsenseapp"
        minSdkVersion 22
        targetSdkVersion 30
        versionCode 66
        versionName "0.60"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }

    ...

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    ...
    //Instrumented tests
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestUtil 'androidx.test:orchestrator:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}

Part of my test class:

@LargeTest
@RunWith(AndroidJUnit4ClassRunner::class)
class AppTest {
    @Rule
    @JvmField
    val rule = ActivityScenarioRule(SplashActivity::class.java)

    @Rule
    @JvmField
    var mGrantPermissionRule =
        GrantPermissionRule.grant(
            "android.permission.READ_PHONE_STATE",
            "android.permission.INTERNET",
            "android.permission.ACCESS_NETWORK_STATE",
            "android.permission.ACCESS_FINE_LOCATION",
            "android.permission.ACCESS_WIFI_STATE"
        )

    @Test
    fun testApp() {
     ...
    }
}

I don't understand at all why AWS Device farm even cannot to start app and fails. Some other AWS devices passes the test ok. All local devices and emulators passes this test ok too. Please help!



from AWS Device Farm - java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.AndroidJUnitRunner"

No comments:

Post a Comment