question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Byte buddy exceptions cause Android instrumented tests to fail.

See original GitHub issue

Background:
I attempted to upgrade a fairly large project from mockitio 1x to 2x. I discovered that mockito 2 tests work only when run using the gradle wrapper, not when launched more directly with adb. The gradle wrapper is sufficient for smaller projects but we are using adb for its ability to shard tests across multiple agents. Mockito 1.x does not have this limitation.

Environment: OS: OSX 10.12.2 IDE: Android Studio 2.3 Beta 2 Android Device: Emulator API 24

Steps:

  1. Create new Android Studio project (Application name: Scheme, Company domain: countolaf.example.com, Min SDK: 19, Type: Empty Activity) NOTE) A single empty unit test has been created on our behalf.
  2. Add mockito dependency to the application’s build.gradle (androidTestCompile org.mockito:mockito-android:2.6.3")
  3. Launch emulator (API 24 in this case)
  4. Build and install the application /gradlew clean installDebug installDebugAndroidTest
  5. Launch instumented tests using gradle ./gradlew connectedAndroidTest
  6. OBSERVE The following exceptions printed to logcat
02-02 13:02:18.410  4181  4196 I art     : Rejecting re-init on previously-failed class java.lang.Class<net.bytebuddy.agent.builder.ResettableClassFileTransformer>: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/instrument/ClassFileTransformer;
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.410  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.410  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.410  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.410  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.410  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
02-02 13:02:18.410  4181  4196 I art     : Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.instrument.ClassFileTransformer" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example.countolaf.scheme.test-2/base.apk", zip file "/data/app/com.example.countolaf.scheme-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.countolaf.scheme.test-2/lib/x86_64, /data/app/com.example.countolaf.scheme-2/lib/x86_64, /system/lib64, /vendor/lib64]]
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.410  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.410  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.410  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.410  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.410  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.410  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
02-02 13:02:18.410  4181  4196 I art     :
02-02 13:02:18.410  4181  4196 E TestLoader: Could not find class: net.bytebuddy.agent.builder.ResettableClassFileTransformer
02-02 13:02:18.432  4181  4196 I art     : Rejecting re-init on previously-failed class java.lang.Class<net.bytebuddy.jar.asm.commons.JSRInlinerAdapter>: java.lang.NoClassDefFoundError: Failed resolution of: Lnet/bytebuddy/jar/asm/tree/MethodNode;
02-02 13:02:18.432  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.433  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.433  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.433  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.433  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.433  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
02-02 13:02:18.433  4181  4196 I art     : Caused by: java.lang.ClassNotFoundException: Didn't find class "net.bytebuddy.jar.asm.tree.MethodNode" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example.countolaf.scheme.test-2/base.apk", zip file "/data/app/com.example.countolaf.scheme-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.countolaf.scheme.test-2/lib/x86_64, /data/app/com.example.countolaf.scheme-2/lib/x86_64, /system/lib64, /vendor/lib64]]
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.433  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.433  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.433  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.433  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.433  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.433  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
02-02 13:02:18.433  4181  4196 I art     :
02-02 13:02:18.434  4181  4196 E TestLoader: Could not find class: net.bytebuddy.jar.asm.commons.JSRInlinerAdapter
02-02 13:02:18.437  4181  4196 I art     : Rejecting re-init on previously-failed class java.lang.Class<net.bytebuddy.jar.asm.commons.TryCatchBlockSorter>: java.lang.NoClassDefFoundError: Failed resolution of: Lnet/bytebuddy/jar/asm/tree/MethodNode;
02-02 13:02:18.437  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.437  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.437  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.437  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.437  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.437  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.437  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.437  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.437  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
02-02 13:02:18.437  4181  4196 I art     : Caused by: java.lang.ClassNotFoundException: Didn't find class "net.bytebuddy.jar.asm.tree.MethodNode" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example.countolaf.scheme.test-2/base.apk", zip file "/data/app/com.example.countolaf.scheme-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.countolaf.scheme.test-2/lib/x86_64, /data/app/com.example.countolaf.scheme-2/lib/x86_64, /system/lib64, /vendor/lib64]]
02-02 13:02:18.437  4181  4196 I art     :   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class java.lang.Class.classForName!(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:400)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.doLoadClass(java.lang.String) (TestLoader.java:92)
02-02 13:02:18.438  4181  4196 I art     :   at java.lang.Class android.support.test.internal.runner.TestLoader.loadIfTest(java.lang.String) (TestLoader.java:113)
02-02 13:02:18.438  4181  4196 I art     :   at void android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(android.support.test.internal.runner.TestLoader, java.util.Set) (TestRequestBuilder.java:801)
02-02 13:02:18.438  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.internal.runner.TestRequestBuilder.build() (TestRequestBuilder.java:747)
02-02 13:02:18.438  4181  4196 I art     :   at android.support.test.internal.runner.TestRequest android.support.test.runner.AndroidJUnitRunner.buildRequest(android.support.test.internal.runner.RunnerArgs, android.os.Bundle) (AndroidJUnitRunner.java:354)
02-02 13:02:18.438  4181  4196 I art     :   at void android.support.test.runner.AndroidJUnitRunner.onStart() (AndroidJUnitRunner.java:260)
02-02 13:02:18.438  4181  4196 I art     :   at void android.app.Instrumentation$InstrumentationThread.run() (Instrumentation.java:1932)
  1. OBSERVE That the exceptions have not caused the unit test to fail.
  2. Run the gradle install tasks again ./gradlew installDebug installDebugAndroidTest
  3. Run the package manager command to display the device’s currently installed instrumented packages adb shell pm list instrumentation, locate test app in output example: instrumentation:com.example.countolaf.scheme.test/android.support.test.runner.AndroidJUnitRunner (target=com.example.countolaf.scheme)
  4. copy the package/runner portion (com.example.countolaf.scheme.test/android.support.test.runner.AndroidJUnitRunner)
  5. Run the same unit tests using the Android activity manager (am) adb shell am instrument -w com.example.countolaf.scheme.test/android.support.test.runner.AndroidJUnitRunner RESULT) The same exceptions have occurred but are considered test failures.

EDIT by @bric3 : improved markdown formatting for better readability

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:31 (22 by maintainers)

github_iconTop GitHub Comments

10reactions
pedronvelosocommented, Jul 30, 2018

I’m proposing this issue be opened again. It hasn’t been fixed on Android Testing Support Library 1.0.0. I’ve actually tested with 1.0.2 and it is still there. Also, the above AOSP patch hasn’t been merged either.

7reactions
tir38commented, Feb 20, 2019

We’re seeing this now from moving from testing 1.0.2 to 1.1.1 (via androidx)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito cannot mock this class: class android.content.Context
1. So, when I tried to raise gradle version directly to the latest 4.x, some issues while running unit tests have popped up..so...
Read more >
Could not initialize inline Byte Buddy mock maker. (This mock ...
What happens instead? tests crashes and gives: Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)...
Read more >
Cannot collect coverage data with Jacoco on regular unit test ...
I want to collect test coverage from my AndroidStudio library using Jacoco. Instrumented tests running on devices work as expected.
Read more >
Byte Buddy - runtime code generation for the Java virtual ...
You can register any bug or misbehavior in Byte Buddy's issue tracker. If possible, please provide a code sample that reproduces the bug....
Read more >
Instrumentation Tests | Android Open Source Project
Your test can make an explicit assertion on pass or fail using JUnit APIs; in addition, any uncaught exceptions will also cause a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found