Skip to content

How to fix error: could not find or load main class org.gradle.wrapper.GradleWrapperMain?

Developing apps for Android is actually rather easy to get into, but once you start working on more complicated projects, you’ll realise how many things you need to account for when working on an app. Programming has come a long way from the old Assembly days, but it’s still difficult for most people to start. 

In this article, we’re taking a look at the “error: could not find or load main class org.gradle.wrapper.GradleWrapperMain” issue when testing a Gradle project, and giving you three fixes to get rid of the issue. 

Also read: How to create an Android App?


Restore the Gradle wrapper

One of the leading reasons why you’re running in this issue is that you’ve deleted or corrupted the Gradle wrapper. In earlier versions, users needed to add a gradle manually to restore the gradle wrapper and all its dependencies. However, newer versions can regenerate it with just a single command.

gradle wrapper

You can supply additional tags such as the gradle-version to specify the gradle version and distribution-type. If you’re on a Mac however, you may need to install gradle before you can run the aforementioned command.

brew install gradle

Also read: How to fix Amazon error 5503?


Commit a gradle wrapper jar

If you’re pulling code from a git repository and seeing the error, the global git ignore can sometimes omit the gradle wrapper jar file which is required for the gradle to generate on command. You can manually add the file by just running this command.

git add -f gradle/wrapper/gradle-wrapper.jar
What is Metadata? Types and benefits | Candid.Technology
Photo by Shahadat Shemul

Check your files

Another very common mistakes that beginners can make when copying over projects is to leave out the wrapper sub folder while copying the gradle folder. This will generate the aforementioned error as your project won’t be able to find or load main class org.gradle.wrapper.GradleWrapperMain. 

Ensure you have the correct folder structure if you’re copying wrapper or your entire project from another location. 

Also read: What is com.android.server.telecom? Everything you need to know

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.

We may earn a commission if you buy something from a link on this page. Thanks for your support.







>