Android Studio: Task 'testClasses' not found in project
Asked Answered
N

7

18

I finally have a Test Case setup for Roboelectric but when I try to run it from Android Studio, get this error: Task 'testClasses' not found in project 'myExternalProjectName'

Error:Could not execute build using Gradle installation 'C:\Users\Mike.gradle\wrapper\dists\gradle-2.2.1-all\c64ydeuardnfqctvr1gm30w53\gradle-2.2.1'.

NOTES: 1. When I run from gradle cmd line(gradlew build) the tests run fine 2. I'M USING : org.robolectric:robolectric:3.0

I have modules in my project as AARs. How can I get around this issue?

Neau answered 7/4, 2016 at 2:46 Comment(3)
anyone have an idea?Neau
#33133496 worked for me.Antho
While this question is old, it's remarkable that all answers are more recent indicating that most people seem to experience the issue in projects with a Kotlin Multiplatform library module. Here is a related question, which explicitly mentions KMP: https://mcmap.net/q/668755/-kmm-project-build-error-39-testclasses-39-not-found-in-project-39-shared-39/2011622.Alikee
D
59

To bypass the error, please add below code in build.gradle

task("testClasses")

This error happens when I rebuild the project and this is from Kotlin Multiplatform plugin/library. Still don't know the actual error cause.

EDIT: The task("testClasses") line should go in the shared module's build.gradle.kts file, within the kotlin { } block.

Diplomat answered 18/2, 2024 at 19:9 Comment(2)
no-one has any comments about how utterly ridiculous this issue is?!Acculturize
I added the line at the end of the file and it also did the jobLoriannlorianna
M
13

I just had this error after setting up signing configs. File -> invalidate caches -> invalidate and restart resolved the issue for me.

Moskow answered 23/10, 2022 at 16:51 Comment(4)
WFM when I got this error after upgrading the KMM plugin.Nonparticipation
Ah interesting, I was setting up a KMM project. Wasn't sure if related but it sounds like it might be.Moskow
This also happened to me in my shared module, I ran ./gradlew clean, synced, and rebuilt the project.Unrestrained
invalidate cache fixed issue. ThanksWherefrom
C
4

Not sure if my comment will be useful, but I've solved that problem with those steps:

  1. Comment "include ':app'" into the setting.gradle.
  2. Try to rebuild. (it'll fail)
  3. Uncomment "include ':app'" into the setting.gradle.
  4. Try to rebuild. Done
Contemptuous answered 28/3, 2024 at 14:0 Comment(1)
wtf , how the hell do this worksCavalierly
K
2

Ashutosh Wahane's solution worked for me, but I think I may have found the culprit of the problem. I'll explain my observations.

In Wahane's solution he add 'task("testClasses")' to the build script. He mentioned that he added it to the Kotlin block of the build script. I added it outside the Kotlin block and his solution still worked. What I noticed was after doing a successful build with that extra line added to the build script, I could then delete that line of code from the build script and things still worked until I did a "clean". At which case I would have to add the line of code again, do a build, and then I once again could go back and delete that extra line of code. If you leave that extra line of code in the build script, it appears that Wahane's solution is a good work around. What I'm not sure is whether that breaks your kmm's shared tests!

With all that said, I started more carefully looking at the build errors I was getting when the error occurs. What I noticed was that I was getting a lot of errors related to the Gradle build configuration cache. I looked at my "gradle.properties" file and saw that it contained the line:

 org.gradle.configuration-cache=true

I set that value to false, and I no longer got the "testClasses" not found error without that extra line added to the build script. From seeing this result, it seems to suggest that the error is a Gradle bug related to using the configuration cache.

If you have problems running tests for the shared kmm code after applying Wahane's solution, then this might be a better workaround solution for you until the configuration cache problem gets fixed in the gradle plugin.

Kirima answered 30/4, 2024 at 18:43 Comment(3)
I'm not sure if the configuration cache is the root of the problem because I'm running into this issue in a project, which hasn't enabled the configuration cache.Alikee
Was your build cache also disabled? I'm not sure if you can even disable the build cache. The behavior I observed and describe, certainly behaves like a cache related issue. I'm a novice in my understanding of Gradle's caching mechanisms.Kirima
still didn't help, it is related to testclasses in latest gradleSedulity
A
1

Ah, I've been there! When facing the 'testClasses' hiccup in Android Studio with Robolectric, it's often a Gradle-related snag. Have you tried syncing Gradle files in Android Studio? Sometimes, a good sync does the trick. Also, ensure your Robolectric version aligns with your Gradle settings. If all else fails, a clean and rebuild could save the day.

Aaberg answered 23/2, 2024 at 2:55 Comment(0)
K
0

Try removing all test configuration first and then run your test from test package.

Steps:

  • step 1.- Go to Run/Debug configuration
  • step 2.- Remove All test configuration file with selecting config and press (-)
  • step 3.- Press Apply and OK
  • step 4.- Run the test again
Ketose answered 27/5, 2018 at 9:33 Comment(0)
N
0

Thats a gradle caching issue.

Here's how I resolved the issue:

Navigate to the Gradle Cache Directory:

  • Open File Explorer.
  • Navigate to C:\Users\username.gradle\caches.
  • Delete the transforms-4 Folder:

Locate the transforms-4 folder in the caches directory.

  • Delete the entire transforms-4 folder. This will remove any corrupted or incomplete files.

Rebuild Your Project:

  • Open your project in your IDE (e.g., Android Studio).

  • Run a clean build to ensure that the caches are rebuilt correctly.

Naaman answered 9/7, 2024 at 23:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.