Gradle wrapper NoClassDefFoundError
Asked Answered
P

4

27

When I run ./gradlew I get

Exception in thread "main" java.lang.NoClassDefFoundError: org/gradle/wrapper/GradleWrapperMain Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

My project compiles using the Android Studio but stopped compiling from command line

Planking answered 4/9, 2014 at 16:29 Comment(4)
A way to bypass it meanwhile: Installed gradle using brew install gradle then run gradle build instead of ./gradlewPlanking
Have You tried running ./gradlew build?Antibiosis
Try using Gal's technique for downloading Gradle and run gradle wrapper to regenerate your wrapper. Perhaps something got mistakenly deleted.Kalamazoo
Make sure you have gradle-wrapper.jar in gradle/wrapper/ under the project dir.Limbert
P
50

Probably something went bad. The solution:

  1. Install gradle: brew install gradle
  2. Regenerate wrapper: gradle wrapper
Planking answered 5/9, 2014 at 21:18 Comment(1)
@MohammadRafayAleem if thisworked then you may wanna accept it as "Accepted Answer" by clicking the thickIntertwine
F
12

See https://github.com/drone/drone/issues/256

My .gitignore had *.jar in it, so I wasn't getting all the jars I needed in my repository.

Fluvial answered 8/6, 2015 at 18:48 Comment(2)
Thank you, this has also been my problem. Without your hint I probably would have searched endlessly.Renferd
In this case, you might consider adding both *.jar and !gradle/wrapper/gradle-wrapper.jar to your .gitignore fileSonni
B
1

I had the same, or similar, problem when trying to build my app from command line, but with an exception thrown for 'java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context' which did not happen when building within Android Studio. I found out that AS brings along it's own JRE and I resolved the issue by setting 'JAVA_HOME' to the AS JRE path. In my case it turned into:

$ JAVA_HOME=/opt/android-studio/jre ./gradlew build

You can find this path under 'File' -> 'Project Structure' -> 'SDK Location', see screenshot.

enter image description here

Baudin answered 19/2, 2018 at 15:25 Comment(0)
B
1

I hit this issue when I have a directory with a ":" (no quotes, just a colon) in it.

This was on a linux machine.

Before:

"my:directory"

as in

/Users/me/projects/project1/my:directory/

then i renamed it to

/Users/me/projects/project1/my_directory/

and the error went away.

Battaglia answered 30/12, 2020 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.