1

My project was working fine on my work PC but after grabbing the same code from git on my MAC I get a bunch of errors.

java: package org.junit does not exist

Error:(6, 23) java: package com.google.gson does not exist

etc

How do I go about fixing this? I'm using Gradle 4.2 and I edited the "Use Local Gradle Location" (Preferences -> Build, Execution, Deployment -> Gradle -> Gradle Home) from the C: drive location to the correct location on my Mac, but I'm having no luck. :(

1
  • After some more investigation, the project structure shows 100 problems e.g. The class path is invalid: Library Gradle: com.beust:jcommander:1.64 has broken sources path: E:/Gradle-4.2/caches/modules-2/files-2.1/com.beust/jcommander/1.64/1b16adc28aca77f62a61f31380f84961c9c3570d/jcommander-1.64-sources.jar How do I go about fixing this? Commented Oct 23, 2017 at 21:27

5 Answers 5

1

I fixed the issue by Invalidating cache and then restart.

File -> Invidate Caches/Restart -> Invidate and restart.

The Android Studio will be forced to rebuild all caches and indices in the next startup.

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure you have junit dependency in your build.gradle, should be something like this:

testCompile group: 'junit', name: 'junit', version: '4.12'

If you have it and it still doesn't work you probably imported your project in wrong way. I don't know what IDE you're using but the correct way would be to find option called "Import Gradle project", that way the IDE will use configuration from you build file.

In case if the problem is not only with org.junit package but with standard java packages like java.util you need to setup java SDK in your IDE.

1 Comment

I'm using Intellij, and I have the above junit dependency within Gradle. I've tried importing, but I'm still get the same issue. It doesn't seem to be reading my build.gradle. "Cannot resolve symbol" compile is underlined in my build.gradle.
0

Fixed the issue by changing the service directory path to match the mac path.

Preferences -> Gradle -> Service directory path: /users/username/.gradle

I also deleted the gradle folder from the home directory

~/user/.gradle/wrapper/dists/gradle-name where gradle-name is the distribution to delete. Then re-opened IntelliJ and opened the project to sync the gradle afresh.

Comments

0

Remove the files that have been generated by your IDE and reimport/recreate the project.

Comments

0

I have had this issue when trying to switch between different versions of dependencies in Gradle, all the above answers are great but if by any chance they do not work, e.g. they didn't work for me initially because my gradle and IntelliJ classpath for dependencies was so muddled.

  1. Try to clean gradle dependencies
  2. As a hail mary, delete your .idea file or your IDE's project config file and reload the project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.