13

My build.gradle for an Android app has become quite lengthy. Chanced upon this plugin called gradle-lint-plugin and configured it properly. In its documentation it says

Run ./gradlew fixGradleLint to automatically fix your build scripts

but upon running that I get Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain.

Does this have anything to do with the Android Studio using its own Gradle plugin? I do not have Gradle installed systemwide.

Edit: I do not wish to install Gradle systemwide - is there any way to do this within Android Studio only?

hongsy
  • 1,498
  • 1
  • 27
  • 39
  • 1
    Possible duplicate of [Could not find or load main class org.gradle.wrapper.GradleWrapperMain](http://stackoverflow.com/questions/29805622/could-not-find-or-load-main-class-org-gradle-wrapper-gradlewrappermain) – petey Jul 21 '16 at 15:17
  • @petey unlike [this question](http://stackoverflow.com/questions/29805622/could-not-find-or-load-main-class-org-gradle-wrapper-gradlewrappermain) I do not have gradle installed - only Android Studio. – hongsy Jul 21 '16 at 15:29
  • try running `./gradlew fixGradleLint` on osx/nix or `gradlew.bat fixGradleLint` on win – petey Jul 21 '16 at 18:42

3 Answers3

32

Sounds like the wrapper is not setup correctly. Likely missing the wrapper jar.

$ ls gradle/wrapper
gradle-wrapper.jar        gradle-wrapper.properties

When you look in gradle/wrapper do you see gradle-wrapper.jar?

if you install gradle you can generate the jar with this command: $ gradle wrapper

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • 1
    Nope - only `gradle-wrapper.properties` is there. Is there any way to fix/run the Gradle task without installing Gradle? – hongsy Jul 21 '16 at 16:18
  • 2
    no at this point you must install gradle to fix. Once you run the command above be sure to commit the jar to git, svn or whatever VCS you are using. After you have the jar you can uninstall gradle and only use the wrapper again but you have to install gradle to fix no matter what. – JBirdVegas Jul 21 '16 at 16:36
  • thank you for your comment! this is testament to how bloated the architecture of Android Studio is. – hongsy Oct 01 '16 at 09:40
  • I already have the wrapper committed but every time react-native-git-upgrade messes the wrapper up so I have to check the file out after the upgrade and it works. – ThaJay Mar 22 '18 at 11:48
  • in my case my `.gitignore` file was configured not to commit `*.jar` so I was able to provide an exception via `!gradle/wrapper/gradle-wrapper.jar` – imnk Nov 11 '21 at 14:50
4

I was having this error and I solved it correcting the path which had special caracters.

Ex: .../T&G/appmobile to ../TG/appmobile

  • A student in a course I was TA in was having a similar problem with a path containing a colon in it. Something along the lines of "/Users/name/22:23/project". It was difficult to figure out what was going wrong but your answer helped us find it. – user11171 Sep 14 '22 at 22:25
1

This sometimes happens if you have "&" or "/" kind of special characters in your folder or in the parent folder. Rename those folders and the error is simply gone.