132

In my flutter project, I have made some updates of plugins and then used flutter upgrade. After that, whenever I am running my flutter project it is showing following error-

    /C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.2/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'.
          io.Platform.packageRoot; // ignore: deprecated_member_use
                      ^^^^^^^^^^^ FAILURE: Build failed with an exception.

* Where: Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

* What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 20s Exception: Gradle task assembleDebug failed with exit code 1

So, I need a suggestion that how can I solve this issue?

3

17 Answers 17

192

You need to upgrade your dependencies to fix this issue, so run:

flutter pub upgrade

If this still doesn't work then it means you are having this issue from transitive dependencies on platform (platform with version lower than 3.1.0 has this problem). So, override the platform package in your pubspec.yaml file like this:

dependency_overrides:
  platform: ^3.1.0
9
  • 2
    I just saw path_provider transitive dependency is also using platform: 3.0.0, and unfortunately, the latest update of path_provider: 2.0.8 doesn't solve this issue, so you'll need to override the dependency as I mentioned in the second part.
    – CopsOnRoad
    Jan 18, 2022 at 14:59
  • Actually @CopsOnRoad it turns out that path_provider has a dependency of platform: ^3.0.0 and not platform: 3.0.0 so doing a flutter pub upgrade is all that is necessary and the override is not required for this case.
    – Maks
    Jan 25, 2022 at 21:34
  • 1
    @Maks I meant it was resolved to platform: 3.0.0 which have this issue. But I was not sure if flutter pub upgrade can actually upgrade the transitive dependencies. I'll update my answer then, thank you
    – CopsOnRoad
    Jan 25, 2022 at 22:40
  • thank you, I am also using path_provider: 2.0.8. I did flutter pub upgrade then done flutter run then it shows a different error. prompt of flutter fix is shown to change the ext.kotlin_version to latest(kotlinlang.org/docs/gradle.html#plugin-and-versions) which in my case was 1.6.10. then I again run flutter run and the issue is fixed. So for me, there is no need for platform: ^3.1.0
    – SKJ
    Feb 5, 2022 at 13:26
  • Confirmed. flutter pub upgrade helped. Especially while switching branches, where the old was had not up-to-date dependencies. Feb 6, 2022 at 19:14
52

Try add in pubspec.yaml file

dependencies: // under dependencies:
  platform: ^3.1.0

then run flutter pub get

Why this error occurred

../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'. io.Platform.packageRoot; // ignore: deprecated_member_use

this is the kind of error that you will get when you build the file.

if you notice the error was caused by package platform:3.0.0

so we are just overriding this by incrementing it to 3.1.0

2
  • Can you get a little bit more in detail, why this is working? Apr 6, 2022 at 8:14
  • As @om-ha stated below, platform pub is out of date. Most likely in your case it's a transitive dependency from path_provider pub
    – Petro
    Apr 30, 2022 at 17:29
34

The only thing that could help me was to delete the pubspec.lock file from the project folder and only then run

flutter clean

flutter pub get
1
  • 8
    Same here. I could never get this working until I deleted pubspeck.lock. Good insight, thank you. Feb 4, 2022 at 3:32
21
flutter pub upgrade

flutter clean

flutter pub get
2
10

Solution

A. deleting pubspec.lock

  • Delete pubspec.lock file
  • For good measures, update platform's parent pub e.g. path_provider to the latest version.
  • flutter pub get

B. pubspec dependency override

  • Add platform with its latest version as a dependency override
dependency_overrides:
  # fix `packageRoot`compile error for iOS, because `path_provider` is using an old version of `platform`
  platform: ^3.1.0 # overrides `path_provider`
  • flutter pub get

Root Cause

  • platform pub is out of date. Most likely in your case it's a transitive dependency from path_provider pub.
  • For some reason, flutter pub get won't update platform which is a transitive dependency. Even if you change the version of its parent pub path_provider to the latest version and call flutter pub get again.

Inspecting platform pub version

A. flutter pub deps to print package dependency graph. Then find "- platform" string within the output.

B. Inside pubspec.lock file, look for "platform:" string.

1
  • 2
    flutter pub get won't update platform which is a transitive dependency. thank you for this! I was trying to figure out why it was needed!
    – Petro
    Apr 30, 2022 at 3:15
9

firstly, run

flutter pub outdated

then

flutter pub upgrade --major-versions

8

For me, cleaning and getting the packages didn't work. This error started after I upgraded flutter. I was on the master channel, a quick fix for me was to switch to stable.

flutter channel stable
flutter upgrade

Perhaps theres a better solution which deals with platform package directly.

2
  • I closed VSCode then clean and pub get. Then it worked like a charm.
    – Ataberk
    Jan 7, 2022 at 23:25
  • Add this under dependencies => dependencies: platform: ^3.1.0. This should be the correct answer Mar 6, 2022 at 17:10
7

I had the same issue and I have solved it with the following steps:

  1. run flutter pub upgrade
  2. run flutter pub outdated
  3. run flutter pub clean

Note: run flutter pub clean in project root and in example packege.

Another important thing make sure you are on the stable version of Flutter.

4

I fixed it with one command:

$ flutter pub cache repair
3

I fixed it : compileSdkVersion 31, and upgrade kotlin-version

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 9, 2022 at 12:01
3

For Flutter iOS Users:

After running following commands:

flutter channel stable
flutter upgrade
flutter pub upgrade

After completing the process, try

pod repo update
pod install

or

pod install --repo-update

Its worked for me. Hope it will be helpful.

2

If all solutions above doesn't work for you just like me,

If the problem occurs immedately you upgrade your flutter

  1. run fluter downgrade 2.0.1 //2.0.1 means your working previous version of flutter
  2. after downgrading, click on the extensions button or use shorcut Ctrl+SHift+X, then uninstall and re-install Flutter and Dart.

this works for me.

2
  1. flutter pub get
  2. flutter pub upgrade

worked for me

1

Update your pubspec.yaml

dependency_overrides:
  platform: ^3.1.0

enter image description here

0

Enter the following into the terminal at the path of your project.

  1. flutter pub cache repair
  2. flutter pub upgrade
2
  • 1
    I would not reccomend updating all the packages like that, most likely things will break
    – Santiago
    Apr 6, 2022 at 15:36
  • 1
    You don't need to update anything in your pubspec.yaml file. this will make sure your updater flutter version also updates SDK in your dependencies.
    – ViKi Vyas
    Apr 25, 2022 at 8:34
0
environment:
  sdk: ">=2.18.2 <3.0.0"

add this to pubspec.yaml

0

I just needed to delete my platform dependency from pubspec.lock. I tried deleting the entire file, but that caused other problems. Deleting the offending entry in this file and then doing these commands worked for me:

flutter clean
flutter pub get
flutter run

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.