Robson112011
Robson112011

Reputation: 11

"Build failed with an exception." in flutter while trying to use sqflite or path_provider

What and when happened?

Error while trying to build a flutter project which uses plugins "sqflite" or "path_provider" (this result bellow is for path_provider, but for sqflite the was almost same failure):

Launching lib\main.dart on Redmi Note 3 in debug mode...

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':path_provider'.
> Could not resolve all artifacts for configuration ':path_provider:classpath'.
   > Could not resolve org.codehaus.mojo:animal-sniffer-annotations:1.14.
     Required by:
         project :path_provider > com.android.tools.build:gradle:3.3.0 > com.android.tools.analytics-library:shared:26.3.0 > com.google.guava:guava:26.0-jre
      > Could not resolve org.codehaus.mojo:animal-sniffer-annotations:1.14.
         > Could not parse POM https://jcenter.bintray.com/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.pom
            > Could not resolve org.codehaus.mojo:animal-sniffer-parent:1.14.
               > Could not resolve org.codehaus.mojo:animal-sniffer-parent:1.14.
                  > Could not parse POM https://jcenter.bintray.com/org/codehaus/mojo/animal-sniffer-parent/1.14/animal-sniffer-parent-1.14.pom
                     > Could not resolve org.codehaus.mojo:mojo-parent:34.
                        > Could not resolve org.codehaus.mojo:mojo-parent:34.
                           > Could not parse POM https://jcenter.bintray.com/org/codehaus/mojo/mojo-parent/34/mojo-parent-34.pom
                              > Resetting to invalid mark
> Could not get unknown property 'android' for project ':path_provider' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

What I tried?

I tried the following:

I also tried removing the related folders in .pub_cache, running pub cache repair, flutter clean, and many others suggestions found around the web, e.g. changing gradle version in build.gradle and gradle-wrapper.properties, and no results.

Environment information

Flutter doctor -v:

[√] Flutter (Channel stable, 1.20.1, on Microsoft Windows [versão 10.0.18363.900], locale pt-BR)
    • Flutter version 1.20.1 at C:\android_sdk\flutter
    • Framework revision 2ae34518b8 (4 days ago), 2020-08-05 19:53:19 -0700
    • Engine revision c8e3b94853
    • Dart version 2.9.0

 
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at C:\android_sdk
    • Platform android-30, build-tools 30.0.0
    • ANDROID_HOME = C:\android_sdk
    • Java binary at: C:\Program Files\Java\jdk1.8.0_261\bin\java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
    • All Android licenses accepted.

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code, 64-bit edition (version 1.47.3)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.13.2

[√] Connected device (1 available)
    • Redmi Note 3 (mobile) • .... • android-arm64 • Android 6.0.1 (API 23)

! Doctor found issues in 1 category.

Pubspec.yaml:

name: testapp
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  decimal: ^0.3.5
  pdf: ^1.9.0
  hive: ^1.4.2
  path_provider: ^1.6.11

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: false
  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

Upvotes: 1

Views: 1800

Answers (2)

Robson112011
Robson112011

Reputation: 11

Solved: I just deleted .gradle folder in user directory.

Upvotes: 0

Bill_The_Coder
Bill_The_Coder

Reputation: 2510

Check pubspec.lock file in your project what folder shared_preferences points to. Remove shared_preferences folder from /.pub-cache/hosted/pub.flutter-io.cn and -Run flutter packages get. -Restart IDE. -Flutter clean -Build now. Try it

Upvotes: 1

Related Questions