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
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