Gradle wrapper NoClassDefFoundError

故事扮演 提交于 2020-07-17 09:32:48

问题


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


回答1:


Probably something went bad. The solution:

  1. Install gradle: brew install gradle
  2. Regenerate wrapper: gradle wrapper



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/25670627/gradle-wrapper-noclassdeffounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!