android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.16k stars 314 forks source link

Junit run listener not found on class path #753

Closed sushantchoudhary closed 4 years ago

sushantchoudhary commented 4 years ago

Description

I updated my test library to latest stable version,

                    test        : "1.3.0",
                    espresso    : "3.3.0",
                    ext         : [
                            junit: "1.1.2"
                    ],
                    orchestrator: "1.3.0"

And started seeing this error in logcat,

2020-09-30 18:00:59.271 7226-7226/com.dummy.android.dummy.core.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dummy.android.dummy.core.debug, PID: 7226
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/internal/runner/listener/InstrumentationRunListener;
        at java.lang.Class.newInstance(Native Method)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5298)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
     Caused by: java.lang.ClassNotFoundException: androidx.test.internal.runner.listener.InstrumentationRunListener
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.newInstance(Native Method) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5298) 
        at android.app.ActivityThread.-wrap2(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/junit/runner/notification/RunListener;
        at java.lang.Class.newInstance(Native Method) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5298) 
        at android.app.ActivityThread.-wrap2(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 

Worked fine in older androidx test version 1.1.0

Steps to Reproduce

Expected Results

Instrumentation test should run successfully

Actual Results

Test runner errors out saying "No tests found" with error in logcat

AndroidX Test and Android OS Versions

AndroidX Test Version : 1.3.0 OS : API 28

Link to a public git repo demonstrating the problem:

sushantchoudhary commented 4 years ago

I tried removing run listener from build.gradle but it still fails with ClassNotFoundException,

2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.junit.runner.notification.RunListener" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.atlassian.android.jira.core.debug.test-1/base.apk", zip file "/data/app/com.atlassian.android.jira.core.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.atlassian.android.jira.core.debug.test-1/lib/x86, /data/app/com.atlassian.android.jira.core.debug-2/lib/x86, /system/lib, /vendor/lib]]
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Object java.lang.Class.newInstance!() (Class.java:-2)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:5298)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.-wrap2(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:-1)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1528)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.os.Looper.loop() (Looper.java:154)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
2020-09-30 20:19:46.185 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.test.internal.runner.listener.InstrumentationResultPrinter>: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/internal/runner/listener/InstrumentationRunListener;
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Object java.lang.Class.newInstance!() (Class.java:-2)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:5298)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.-wrap2(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:-1)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1528)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.os.Looper.loop() (Looper.java:154)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
2020-09-30 20:19:46.186 9252-9252/com.atlassian.android.jira.core.debug I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
adazh commented 4 years ago

It sounds like it's due to proguard. Do you proguard your test app? Try removing proguard and see if it fixes the issue.

If it still does not work, could you send us a full sample? We'll need a full sample to repro the issue. Thanks!

sushantchoudhary commented 4 years ago

Thanks @adazh , removing it might not be feasible but I will the review the proguard rules in case there is way to keep these classes or not get warned. Being said, not sure how it worked for androidx test version 1.1.0

adazh commented 4 years ago

We generally do not recommend testing against proguarded apps, but yeah... you can try and see if you can keep the classes for testing.

I'll close the issue for now. Please feel free to re-open if you need further help.