Error: Member not found: 'packageRoot', how to solve ignore: deprecated_member_use in Flutter?

AndroidIosFlutterDart

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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

Solution 4 - Android

flutter pub upgrade

flutter clean

flutter pub get

Solution 5 - Android

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.

Solution 6 - Android

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.

Solution 7 - Android

firstly, run

flutter pub outdated

then

flutter pub upgrade --major-versions

Solution 8 - Android

I fixed it with one command:

$ flutter pub cache repair

Solution 9 - Android

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.

Solution 10 - Android

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.

Solution 11 - Android

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

Solution 12 - Android

Update your pubspec.yaml

dependency_overrides:
  platform: ^3.1.0

enter image description here

Solution 13 - Android

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.

Solution 14 - Android

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

  1. flutter pub cache repair
  2. flutter pub upgrade

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionS. M. AsifView Question on Stackoverflow
Solution 1 - AndroidCopsOnRoadView Answer on Stackoverflow
Solution 2 - AndroidEslam NassrView Answer on Stackoverflow
Solution 3 - AndroidAlexView Answer on Stackoverflow
Solution 4 - AndroidLinarView Answer on Stackoverflow
Solution 5 - AndroidArkayView Answer on Stackoverflow
Solution 6 - AndroidTalat El BeickView Answer on Stackoverflow
Solution 7 - AndroidAhmad hassanView Answer on Stackoverflow
Solution 8 - AndroidYauheni PrakapenkaView Answer on Stackoverflow
Solution 9 - AndroidDatapalaceView Answer on Stackoverflow
Solution 10 - AndroidPratik ButaniView Answer on Stackoverflow
Solution 11 - AndroidYuNang WuView Answer on Stackoverflow
Solution 12 - AndroidUmer Waqas CEO FluttydevView Answer on Stackoverflow
Solution 13 - Androidom-haView Answer on Stackoverflow
Solution 14 - AndroidViKi VyasView Answer on Stackoverflow