Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMainShort answer
The gradlew script starts Java with gradle/wrapper/gradle-wrapper.jar, and that JAR does not exist or is damaged. Typical causes are a .gitignore rule for *.jar or an incomplete copy. Regenerate the wrapper with an installed Gradle and commit the JAR.
Fix it fast
1Find out which cause you have
Check that the wrapper JAR exists and is not empty.
ls -l gradle/wrapper/2Match what you see, then jump to its fix
What does the error look like?
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMainCaused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
Cause 1 of 2
gradle-wrapper.jar is missing because Git ignores jar files
1Check
A global or project .gitignore with *.jar keeps the JAR out of the repository, so a clone lacks it.
git check-ignore -v gradle/wrapper/gradle-wrapper.jar
git ls-files gradle/wrapper2Fix
Add an exception rule for the wrapper JAR, regenerate it, and commit. Gradle's documentation says to put the JAR in version control.
# .gitignore
!gradle/wrapper/gradle-wrapper.jar3Verify
The JAR is tracked.
git add -f gradle/wrapper/gradle-wrapper.jar
git ls-files gradle/wrapperConfirmed by docs.gradle.org
Cause 2 of 2
The JAR is present but damaged or from a bad copy
1Check
A damaged or incompletely copied JAR fails to load. Compare its SHA-256 with the published checksum for your Gradle version.
ls -l gradle/wrapper/gradle-wrapper.jar
shasum -a 256 gradle/wrapper/gradle-wrapper.jar2Fix
Regenerate it. With a Gradle installed, run the wrapper task from the project root, then run it once more so the JAR and scripts are both refreshed.
gradle :wrapper
./gradlew :wrapper3Verify
Gradle starts and prints its version.
./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Keep all four wrapper files in Git and add a CI step that fails if gradle-wrapper.jar is untracked.
- Check the wrapper JAR checksum against Gradle's published list when it comes from outside your team.
- Update the wrapper with the wrapper task, not by copying files from another project.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
./gradlew will not run: permission denied
zsh: permission denied: ./gradlew
The gradlew script has lost its executable bit, usually after a zip download, a Windows checkout or a copy to another disk.
3 causes, each with a fixMobile apps
Android app crashes because the Apache HTTP classes are missing
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fix