cannot run the unit test in TODO-MVP
/* Remove this comment todo-mvp */
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.example.android.architecture.blueprints.todoapp.util.AppExecutors.
Test running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
That java.lang.IllegalAccessError in TODO-MVP is a known issue that pops up when running instrumentation tests on older Android project setups like android-architecture’s todo-mvp sample. It’s usually not because your logic is wrong — it’s because the test runtime is mixing incompatible class versions due to Gradle/Android plugin/test runner mismatches.
Let’s break down what’s going on and how to fix it.
Why it happens The project was created years ago (2017–2018), and its Gradle, Android plugin, and dependencies are outdated.
On Android, IllegalAccessError during tests often means:
A class was pre-verified against one implementation during compilation but found a different one at runtime.
You have different versions of the same dependency between main and androidTest classpaths.
In TODO-MVP, AppExecutors is likely using Java 8 concurrency classes and Android support libraries, but the instrumentation test environment is loading older/different versions.
How to fix it Here’s the step-by-step fix that works for this repo:
- Update the test runner & dependencies Open app/build.gradle and change:
android { defaultConfig { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } }
dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } If the project still uses com.android.support.test, replace it with androidx.test equivalents. Also, ensure you run ./gradlew app:dependencies to confirm you have only one version of androidx.annotation and androidx.test artifacts.
- Migrate to AndroidX (if not done) If the code still has android.support.* imports:
In Android Studio: Refactor → Migrate to AndroidX
This ensures the test runner and your main app classes are using the same classloader.
- Match JDK & Gradle plugin versions In gradle.properties:
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true android.enableJetifier=true In build.gradle (project-level):
classpath "com.android.tools.build:gradle:8.2.2" And make sure your Gradle wrapper (gradle/wrapper/gradle-wrapper.properties) is at least:
distributionUrl=https://services.gradle.org/distributions/gradle-8.2-bin.zip 4. Clean & Rebuild After dependency alignment:
./gradlew clean ./gradlew connectedAndroidTest 5. If it still fails For older Dalvik/ART runtime bugs, you can disable pre-verification by running tests with:
./gradlew connectedAndroidTest -Pandroid.injected.testOnly=false Or, for local debug purposes, make AppExecutors use a simpler implementation in androidTest (mock executors).
In short: This error is not because of your AppExecutors code — it’s a classpath conflict between test and app due to outdated dependencies. Updating to AndroidX test runner, aligning dependencies, and migrating to modern Gradle versions fixes it.