Fixed - expected to find project root in current working directory in flutter


Error: "Expected to find project root in the current working directory."

This error in Flutter OneSignal integration occurs when the plugin cannot locate the root directory of your Flutter project. OneSignal requires proper project structure and configuration to function correctly.

Solution:

  1. Verify Flutter Project: Ensure that you are in the root directory of your Flutter project. Navigate to the root directory using the terminal before running OneSignal commands.

    Example:

              cd /path/to/your/flutter/project
            

  2. Run Commands from Project Root: Make sure you execute the OneSignal commands from the root directory of your Flutter project. This is crucial for the plugin to locate the necessary files and configurations.

    Example:

              flutter pub get
              flutter pub run onesignal_flutter:plugin
            

  3. Check OneSignal Configuration: Verify that your OneSignal configuration is correctly set up in the `pubspec.yaml` file. Ensure that you have added the necessary dependencies and configuration details.

    Example:

              dependencies:
                onesignal_flutter: ^
    
              onesignal:
                appid: "your_app_id"
                apiKey: "your_api_key"
                // Other OneSignal configurations
            

  4. Update OneSignal Plugin: Ensure that you are using the latest version of the OneSignal Flutter plugin. Update your `pubspec.yaml` file to include the latest version and run `flutter pub get` to fetch the updated plugin.

    Example:

              dependencies:
                onesignal_flutter: ^
            

  5. Clean and Rebuild: After making changes, clean your project and rebuild it. This ensures that any cached or outdated configurations are cleared, and the new settings take effect.

    Example:

              flutter clean
              flutter build
            

After following these steps, try running your OneSignal commands again. If the issue persists, double-check your project structure, configurations, and consult the OneSignal Flutter documentation for any specific requirements.


I think, you are not in your root directory of the your project. For Example: If your project is in D:\AllProjects\MyProject then make sure you are in this directory before running the command. Also, share the screenshot of the error.
First, ensure that all environmental variables are valid and correct. You may need to restart the terminal (cmd or your PC) for the changes to take effect. If that doesn't work, you can try setting PATH in cmd/terminal. This usually resets the PATH in cmd (not the Environmental Variables) to the new variable specified. To avoid overwriting the existing PATH, use the following command: set path=%PATH%;C:\Program Files\Git\bin;C:\...
I'm not able to run commands like 'flutter run' or 'flutter build apk' using the terminal inside Android Studio at my Project Root Directory. However, the same commands run perfectly well while running in the flutter_console.bat located in the Flutter SDK folder. Therefore, I simply change the path to the Project Root Directory in flutter_console.bat and generate the APK using the 'flutter build apk --release' command.