Search code examples
javaandroidandroid-studiogradlew

:app:compileDebugUnitTestJavaWithJavac FAILED Android Studio


I have searched to a good degree on stack overflow etc to try find an answer to my question. I have so far been unable to find any solution that works for my specific problem.

Up until the 5th of February, When I ran the command:

.\gradlew test

The command would complete and the build would be successful. Today (7th), I pulled changes from my teams remote repo. When I ran the command I would get the below output:

:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidEmbedded310Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:compileDebugUnitTestJavaWithJavac FAILED

BUILD FAILED

Total time: 5.804 secs

I created a new branch to see if I could figure out what commit was causing the issue, however, when I checked out a commit that I knew for certain did not contain issues (the commit I had previously been at) and attempted to run the command I would get similar output.

Similarly I used to be able to simply right click on my test file and select "Run whateverTest.java" and the test would run.

Now when I attempt the same thing I get the following output:

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:191)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:174)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code -3

Now I must select the file and select "Run..." from the run tile. This will run my tests successfully.

I have attempted the ususal build, clean restart computer etc. I have also attempted to create a JAVA_HOME and ANDROID_JAVA_HOME environment variable (under recommendation of similar questions).

Since that time the only thing that sticks out to me is that there was a java update. I suspect this may be the cause but I am not certain.

I would appreciate any help and I can provide any more details that are required.

Thanks.

UPDATE

For more context here is more of the output from .\gradlew test

* What went wrong:
Execution failed for task ':app:compileDebugUnitTestJavaWithJavac'.
> Could not find tools.jar

Hopefully this gives better context.


Solution

  • SOLVED

    Problem was solved by uninstalling both Java and Android Studio and then reinstalling them.

    I believe there was a path hidden somewhere in Android Studio that I was unable to change that took a reinstall for me to be prompted to select.