NoClassDefFoundError when running unit test with Gradle task

After searching further about this issue, I found it also being reported in the android-test and app-bundle-samples projects and there is also an issue in the issue tracker.

It turns out this issue fixed in the Android Gradle Plugin 4.1.0 as per comment in the issue tracker.

If you don't want to update AGP to 4.1.0 which is still in alpha, adding this to the feature module's build.gradle fixed the issue for me, as per this comment:

testRuntimeOnly(files("$projectDir/../b_app/build/intermediates/app_classes/debug/classes.jar"))