Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : Could not determine the dependencies of task ':shared_preferences:compileDebugAidl'

Tags:

flutter

dart

I create new app in flutter and it's work when I run it, but when I add shared_preferences package, I got this error when I run it

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':shared_preferences:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':shared_preferences:debugCompileClasspath'.
   > Could not resolve project :shared_preferences_macos.
     Required by:
         project :shared_preferences
      > Unable to find a matching configuration of project :shared_preferences_macos:
          - None of the consumable configurations have attributes.
   > Could not resolve project :shared_preferences_web.
     Required by:
         project :shared_preferences
      > Unable to find a matching configuration of project :shared_preferences_web:
          - None of the consumable configurations have attributes.

* 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 866ms
Gradle task assembleDebug failed with exit code 1

this is my pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.3+1

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

What is wrong with that, and how I can solve it? help me please... thanks

like image 823
Ashta Avatar asked Dec 13 '22 09:12

Ashta


2 Answers

I was able to solve this problem by running the following command:

$ flutter pub cache repair
like image 192
Marcos Avatar answered Mar 30 '23 00:03

Marcos


This issue exists
Use fix version like following as workaround, remove ^
shared_preferences: 0.5.3+1

I have tested without error

full test code

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: _incrementCounter,
          child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}
like image 36
chunhunghan Avatar answered Mar 30 '23 01:03

chunhunghan