0
Exception from flutter run: Exception: Unable to locate Gradle. Please configure the path to Gradle using `flutter config --gradle-dir`.
package:flutter_tools/src/base/common.dart 31              throwToolExit
package:flutter_tools/src/android/gradle.dart 115          buildGradleProject.<async>
dart:async/future.dart 184                                 Future.Future.microtask.<fn>
package:stack_trace/src/stack_zone_specification.dart 185  StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 97   StackZoneSpecification._registerCallback.<fn>
package:stack_trace/src/stack_zone_specification.dart 185  StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 97   StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1146                                  _rootRun
dart:async/zone.dart 1026                                  _CustomZone.run
dart:async/zone.dart 924                                   _CustomZone.runGuarded
dart:async/zone.dart 951                                   _CustomZone.bindCallback.<fn>
package:stack_trace/src/stack_zone_specification.dart 185  StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 97   StackZoneSpecification._registerCallback.<fn>
package:stack_trace/src/stack_zone_specification.dart 185  StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 97   StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1150                                  _rootRun
dart:async/zone.dart 1026                                  _CustomZone.run
dart:async/zone.dart 924                                   _CustomZone.runGuarded
dart:async/zone.dart 951                                   _CustomZone.bindCallback.<fn>
dart:async/schedule_microtask.dart 41                      _microtaskLoop
dart:async/schedule_microtask.dart 50                      _startMicrotaskLoop
dart:isolate-patch/isolate_patch.dart 96                   _runPendingImmediateCallback
dart:isolate-patch/isolate_patch.dart 149                  _RawReceivePortImpl._handleMessage
===== asynchronous gap ===========================

If I run flutter config in the terminal, flutter command not found exception is thrown in the terminal.

4

1 回答 1

2

This is the code which tries to find gradle: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/android/gradle.dart#L37

The flutter command is located inside the bin directory of the flutter SDK you downloaded. Adding it to your path is covered in our setup docs: https://flutter.io/setup/#get-the-flutter-sdk

You can specify the location of your gradle binary using args to the commands or globally using flutter config with the --gradle-dir or --android-studio-dir flags.

As you can see in the linked code, we know how to find gradle in some default locations, such as inside /Applications/Android Studio.app or by reading your path variable. We probably could add more default locations.

If you believe your Android SDK is installed in a default location we're not checking please file a bug at https://github.com/flutter/flutter/issues/new and we're happy to fix.

于 2017-01-25T16:21:30.667 回答