Your gradle wrapper is missing, broken or corrupted.
—
What is gradle wrapper:
gradlew
is the gradle wrapper executable — batch script on windows and shell script elsewhere. The wrapper script when invoked, downloads the defined gradle version and executes it. By distributing the wrapper with your project, anyone can work with it without needing to install Gradle beforehand. Even better, users of the build are guaranteed to use the version of Gradle that the build was designed to work with.
—
Restoring gradle wrapper:
It used to be that you needed to add a wrapper
task to your build.gradle
to restore gradle wrapper and all its dependencies. For instance in build.gradle
:
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
Or in build.gradle.kts
:
tasks.register<Wrapper>("wrapper") {
gradleVersion = "4.1"
}
Newer versions of gradle do not require this. It is now a built-in task. Just run:
gradle wrapper
You can also supply additional flags to specify versions etc
gradle wrapper --gradle-version 6.2 --distribution-type all
When you run this task, a gradle wrapper script, and the required jar files are added to your source folders. Properties are stored in gradle/wrapper/gradle-wrapper.properties
(You may need to install gradle locally to run this. brew install gradle
on mac for instance. See more detailed instructions here)
—
Why was it missing in the first place?
OP seems to have deleted something that gradle wrapper depends on.
But a common reason is that a .gitignore entry prevents wrapper jars from being checked into git. Note that the .gitignore in effect may be in the source folder, or a global one in your user home folder or git global configuration. It is common to have a *.jar
entry in .gitignore.
You can add an exception for gradlew’s jar files in .gitignore
*.jar
!gradle/wrapper/gradle-wrapper.jar
or force add the wrapper jar into git
git add -f gradle/wrapper/gradle-wrapper.jar
—
Ref: Gradle Wrapper
Steps to Reproduce
- Create a project using the latest released Flutter.
- Upgrade it from Gradle as described here.
- Try and run the project.
Logs
I get this output from IntelliJ:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Finished with error: Exit code 1 from: /Users/me/Tim/quicktimer/android/gradlew -v:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
I’ve tried quite a lot to solve this. In fact opening the android
subfolder in Android Studio works fine and builds the APK without errors, so I really have no idea why this is happening. All the solutions on Google involve running gradle wrapper
to regenerate the wrapper that will download the correct version of Gradle or something like that, but I don’t know how to run gradle
. It isn’t in my PATH
. I assume it is embedded in IntelliJ somewhere. Bit of a catch-22.
Flutter Doctor
[✓] Flutter (on Mac OS X 10.13.2 17C88, locale en-GB, channel alpha)
• Flutter at /Users/me/Tim/flutter
• Framework revision 8f65fec5f5 (7 weeks ago), 2017-12-12 09:50:14 -0800
• Engine revision edaecdc8b8
• Tools Dart version 1.25.0-dev.11.0
• Engine Dart version 2.0.0-edge.d8ae797298c3a6cf8dc9f4558707bd2672224d3e
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/me/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[-] iOS toolchain - develop for iOS devices
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup
[✓] Android Studio (version 3.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] IntelliJ IDEA Community Edition (version 2017.3.3)
• Flutter plugin version 21.1.3
• Dart plugin version 173.4301.22
[✓] Connected devices
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
I too am experiencing this issue. Freshly setup Flutter within VS Code on macOS. Android Studio v3 installed. New Flutter project, all Android builds result in the following error:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Exit code 1 from: /Users/joshkahane/Desktop/Dart:Flutter Test/hello_world/android/gradlew -v:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Exited (sigterm)
Opening the subfolder as a project in Android Studio runs without issues.
I resolved my issue by removing a forward slash ‘/’ from a folder name my project was kept in. That / is translated into a ‘:’ and it doesn’t like it!
What’s the output of flutter doctor -v
after
Freshly setup Flutter
- Delete the flutter cache (
<installation folder>/bin/cache
); - Delete
gradlew
andgradlew.bat
inandroid
folder (and in some casesandroid/gradle/wrapper/gradle-wrapper.jar
too); - Run
flutter run
again.
This steps worked for me.
Slight tweak to @danielborges93’s comment — I deleted the gradlew
file in android
folder (along with the above steps), and it now works.
It did not work for me.
I created a new project and moved the old files.
I had the same issue, and adding a gradle-wrapper.jar worked: /your-project/android/gradle/wrapper/gradle-wrapper.jar. you can find this jar file from any Android project
I am facing the same issue. Here is the log. Any help much appreciated. it was just fine today morning.
cat /Users/dhanasekarapandiansrinivasan/Development/MyFlutterApp:Mobile/MyFlutterApp/Mobile/flutter_03.log;
Flutter crash report; please file at https://github.com/flutter/flutter/issues.
command
flutter run -t lib/home/main.dart -d Android SDK built for x86
exception
ProcessException: ProcessException: Process «/Users/dhanasekarapandiansrinivasan/Development/MyFlutterApp:Mobile/MyFlutterApp/Mobile/android/gradlew» exited abnormally:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Command: /Users/dhanasekarapandiansrinivasan/Development/MyFlutterApp:Mobile/MyFlutterApp/Mobile/android/gradlew -v
#0 runCheckedAsync (package:flutter_tools/src/base/process.dart:251:5)
<asynchronous suspension>
#1 _initializeGradle (package:flutter_tools/src/android/gradle.dart:185:9)
<asynchronous suspension>
#2 _ensureGradle (package:flutter_tools/src/android/gradle.dart:166:37)
<asynchronous suspension>
#3 _readGradleProject (package:flutter_tools/src/android/gradle.dart:95:31)
<asynchronous suspension>
#4 _gradleProject (package:flutter_tools/src/android/gradle.dart:87:34)
<asynchronous suspension>
#5 getGradleAppOut (package:flutter_tools/src/android/gradle.dart:81:29)
<asynchronous suspension>
#6 AndroidApk.fromAndroidProject (package:flutter_tools/src/application_package.dart:96:23)
<asynchronous suspension>
#7 getApplicationPackageForPlatform (package:flutter_tools/src/application_package.dart:283:30)
<asynchronous suspension>
#8 FlutterDevice.runHot (package:flutter_tools/src/resident_runner.dart:269:21)
<asynchronous suspension>
#9 HotRunner.run (package:flutter_tools/src/run_hot.dart:272:39)
<asynchronous suspension>
#10 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:398:37)
<asynchronous suspension>
#11 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:401:18)
<asynchronous suspension>
#12 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:335:33)
<asynchronous suspension>
#13 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:142:29)
<asynchronous suspension>
#14 _rootRun (dart:async/zone.dart:1124:13)
#15 _CustomZone.run (dart:async/zone.dart:1021:19)
#16 _runZoned (dart:async/zone.dart:1516:10)
#17 runZoned (dart:async/zone.dart:1463:12)
#18 AppContext.run (package:flutter_tools/src/base/context.dart:141:18)
<asynchronous suspension>
#19 FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:326:20)
#20 CommandRunner.runCommand (package:args/command_runner.dart:196:27)
<asynchronous suspension>
#21 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:401:21)
<asynchronous suspension>
#22 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:142:29)
<asynchronous suspension>
#23 _rootRun (dart:async/zone.dart:1124:13)
#24 _CustomZone.run (dart:async/zone.dart:1021:19)
#25 _runZoned (dart:async/zone.dart:1516:10)
#26 runZoned (dart:async/zone.dart:1463:12)
#27 AppContext.run (package:flutter_tools/src/base/context.dart:141:18)
<asynchronous suspension>
#28 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:361:19)
<asynchronous suspension>
#29 CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:111:29)
#30 new Future.sync (dart:async/future.dart:224:31)
#31 CommandRunner.run (package:args/command_runner.dart:111:11)
#32 FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:241:18)
#33 run.<anonymous closure> (package:flutter_tools/runner.dart:60:20)
<asynchronous suspension>
#34 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:142:29)
<asynchronous suspension>
#35 _rootRun (dart:async/zone.dart:1124:13)
#36 _CustomZone.run (dart:async/zone.dart:1021:19)
#37 _runZoned (dart:async/zone.dart:1516:10)
#38 runZoned (dart:async/zone.dart:1463:12)
#39 AppContext.run (package:flutter_tools/src/base/context.dart:141:18)
<asynchronous suspension>
#40 runInContext (package:flutter_tools/src/context_runner.dart:43:24)
<asynchronous suspension>
#41 run (package:flutter_tools/runner.dart:51:10)
#42 main (package:flutter_tools/executable.dart:51:9)
<asynchronous suspension>
#43 main (file:///Users/dhanasekarapandiansrinivasan/Development/flutter/packages/flutter_tools/bin/flutter_tools.dart:8:3)
#44 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:287:32)
#45 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
flutter doctor
[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.14.1 18B75, locale en-US)
• Flutter version 1.0.0 at /Users/dhanasekarapandiansrinivasan/Development/flutter
• Framework revision 5391447fae (3 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /Users/dhanasekarapandiansrinivasan/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 1.9.4
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[✓] VS Code (version 1.30.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.21.0
[✓] Connected device (3 available)
• SM G960U • 4545525a44553398 • android-arm64 • Android 8.0.0 (API 26)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• Dsp • 00008020-001A596A363A002E • ios • iOS 12.1.1
• No issues found!
I had this one also, tried all sorts but in the end, it turned out to be an ampersand in one of the parent directories where my project was located. Renaming the folder to remove the offending ‘&’ fixed this issue for me.
None of the above worked, @HarveyStroud suggestion worked. Thanks. My path had a ‘:’ in it.
I had this one also, tried all sorts but in the end, it turned out to be an ampersand in one of the parent directories where my project was located. Renaming the folder to remove the offending ‘&’ fixed this issue for me.
My goodness. I spent hours and hours trying to figure this issue out and it turns out the ampersand was my issue. Incredible. Thank you so much.
No problem, I’m glad I could be of help
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
lock
bot
locked and limited conversation to collaborators
Apr 15, 2020
1. Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
If you’re running into this issue, it’s because you’re missing this file: android/gradle/wrapper/gradle-wrapper.jar .
You can generate this binary by simply running
gradle wrapper
in the project’s android folder. If you don’t have gradle installed, follow gradle documentation on how to install it (or just run “brew install gradle” on MacOS).
2. SDK Location not found
If you’re running into this issue when building a React Native mobile app on Android, it’s because your Android SDK path is broken or it doesn’t exist. Open your ~/.bash_profile, and add the following lines at the beginning:
export ANDROID_HOME=~/Library/Android/sdk/ export PATH=~/Library/Android/sdk/tools:$PATH export PATH=~/Library/Android/sdk/platform-tools:$PATH
Now load the new ~/.bash_profile in your Terminal (restart the Terminal or run “source ~/.bash_profile“), and re-run the Android app.
3. Keystore file ‘…android/app/debug.keystore’ not found for signing config ‘debug’.
You can fix this error by simply running the following command in your android/app folder and typing in all the requested information:
keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
4. warn Failed to connect to development server using “adb reverse”: spawnSync adb ENOENT
This is just an warning, and it means the build was successful, but it couldn’t open the app. Check out the app on your emulator / android device, and simply open it manually.
Could not find or load main class org.gradle.wrapper.GradleWrapperMain
-
179 - August 4, 2018
Sometime you may face error “Could not find or load main class org.gradle.wrapper.GradleWrapperMain” while working with Gradle project which is very difficult to find out the root cause of the issue. In this article, we’ll explain the root cause of the issue and how to resolve this.
Issue Description
Could not find or load main class org.gradle.wrapper.GradleWrapperMain. Bitbucket pipeline or Jenkins console output, the build is failed – “Could not find org.gradle.wrapper.GradleWrapperMain”
The symptom of the issue
This error will be thrown when we are trying to clean or build the Gradle project and gradlew build unable to find the gradle folder which contains the gradle-wrapper.jar file. This might be possible developer has missed out to check-in the Gradle folder in the repository.
Solution
If wrapper folder doesn’t exist under gradle folder then create the wrapper folder and paste gradle-wrapper.jar & grade-wrapper.properties in the wrapper folder.
Project structure should be as below
–gradle-wrapper.jar
–gradle-wrapper.properties
Post this, try to build the project again and you will notice that the error is no more.
Post Views: 230