flutter / devtools

Performance tools for Flutter
https://flutter.dev/docs/development/tools/devtools/
BSD 3-Clause "New" or "Revised" License
1.57k stars 323 forks source link

[deeplink] Path of my flutter project is not recognized #7747

Open sbatezat opened 4 months ago

sbatezat commented 4 months ago

I'm trying to debug deep links as per this documentation https://docs.google.com/document/d/1fnWe8EpZleMtSmP0rFm2iulqS3-gA86z8u9IsnXjJak

It's asked to enter the path of the local project, but it seems my project cannot be well scanned. I'm always having the error dialog "You selected a non Flutter project".

My path looks like this /Users/USERNAME/dev/MyApp

What's wrong?


DevTools version: 2.31.1 IDE: VSCode Connected Device: CPU / OS: arm64 (64 bit) android Connected app type: Flutter native (debug build) Dart Version: 3.3.4 Flutter Version: 3.19.6 / stable Framework / Engine: 54e66469a9 / c4cd48e186

sbatezat commented 4 months ago

I've just upgraded my Flutter SDK from 3.19.6 to 3.22.0 and so my DevTools is now 2.34.3. The problem is still there (my project path appears on the new combo box, but when I click on the "validate deep links" button, a popup still claims this is not a Flutter project)

kenzieschmoll commented 4 months ago

@chunhtai @hangyujin

hangyujin commented 4 months ago

Hi @sbatezat , to help me understand the bug better

  1. Are you using the devtool in a browser or in vscode/android studio? If you have a screenshot , it will be helpful.
  2. Are other functions in the devtool working properly for this app? For example, inspector, memory
sbatezat commented 4 months ago

Hi @hangyujin

  1. The information is on the issue, I'm using VSCode. However, I've tested it on a Chrome browser and the result is the same.
  2. Others functions are working properly

I can't see how screenshot can help, but here it is :-)

image

CoderDake commented 4 months ago

@sbatezat are you using windows? there is currently a bug that looks similar to what you are seeing.

sbatezat commented 4 months ago

@sbatezat are you using windows? there is currently a bug that looks similar to what you are seeing.

@CoderDake No, I'm not targetting Windows and I'm working on macOS

hpelitebook745G2 commented 3 months ago

i'm also getting this issue, any updates?

hangyujin commented 3 months ago

https://github.com/flutter/devtools/pull/7767 @chunhtai just merged a PR to show more error messages if the path is not recognized. It will help this issue. It can happen due to many reasons, maybe the devtool server is not running, maybe the analyze command failed.

hangyujin commented 3 months ago

Can you run the command "flutter analyze --android --list-build-variants" in terminal under your project path (for example: "/Users/USERNAME/dev/MyApp") to see if it can successfully get build variants?

sbatezat commented 3 months ago

Can you run the command "flutter analyze --android --list-build-variants" in terminal under your project path (for example: "/Users/USERNAME/dev/MyApp") to see if it can successfully get build variants?

flutter analyze --android --list-build-variants
Running Gradle task 'printBuildVariants'...                        10,3s

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/USERNAME/dev/MyApp/android/app/build.gradle' line: 55

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method applicationId() for arguments [[]] on DefaultConfig$AgpDecorated_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=[], buildConfigFields={}, resValues={}, proguardFiles=[], consumerProguardFiles=[], manifestPlaceholders={applicationName=android.app.Application}, wearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.DefaultConfig$AgpDecorated.

* 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 9s

I understand why the command is failing. I'm using --dart-define-from-file "env/. development.env" to run/debug my app, and this is adding dynamically an application id on the app. Without that option, there is no application id, and your command is failing.

Here is how it's implemented on build.gradle

def dartEnvironmentVariables = [];
if (project.hasProperty('dart-defines')) {
    dartEnvironmentVariables = project.property('dart-defines')
        .split(',')
        .collectEntries { entry ->
            def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
            [(pair.first()): pair.last()]
        }
}

android {
    defaultConfig {
        applicationId dartEnvironmentVariables.ANDROID_APPLICATION_ID
    }
}

Here is the VSCode configuration to take this into account from the IDE

{
            "name": "Android - DEV",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart",
            "toolArgs": [
                "--dart-define-from-file", "env/.development.env"
            ]
},

How can I solve that issue?

chunhtai commented 3 months ago

Hi @sbatezat

Can you try to create an example project with the setup you describe? that way it will be easier for us to try to figure out how to support your use case

talamaska commented 2 months ago
[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [Version 10.0.22631.3737], locale bg-BG)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.3)
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.90.2)
[√] Connected device (4 available)
[√] Network resources

Tested with the sample counter app, and one a bit more complicated with GoRouter and Shell routes. Both projects not recognised as flutter apps. One was just generated by the cli.

Running Gradle task 'printBuildVariants'... 48,4s ["debug","release","profile"]

Using the deep links test tool inside vs code and in browser The issue I have identified is related to the paths to flutter apps in the dropdown. image

When the path is typed correctly in the field the deep link checker works

C:\DeveloperArea\flutter_projects\test_original_flutter

sbatezat commented 2 months ago

@chunhtai I didn't had time to create a whole sample project and do not know where to host it. You can reproduce this issue anywhere and very quickly using these steps :

  1. Create a file "development.env" at the root path of your project
{
    "APPLICATION_ID": "com.my.app.id"
}
  1. Edit your android/app/build.gradle file with this after the plugin section :
def dartEnvironmentVariables = [];
if (project.hasProperty("dart-defines")) {
    dartEnvironmentVariables = project.property("dart-defines")
        .split(',')
        .collectEntries { entry ->
            def pair = new String(entry.decodeBase64(), "UTF-8").split("=")
            [(pair.first()): pair.last()]
        }
}
  1. Still on the build.gradle file, edit the application id defaultConfig like that :
    defaultConfig {
        applicationId dartEnvironmentVariables.APPLICATION_ID
        ...
    }
  1. Verify that your application is working well using "--dart-define-from-file" on your run command. Here an example with a custom launch config for VSCode if you are using that IDE (.launch.json file)
{
            "name": "Android - DEV",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart",
            "toolArgs": [
                "--dart-define-from-file", "development.env"
            ]
}
  1. Here we are, you are unable to have deepLinks devtool working well.
bsutton commented 2 months ago

I'm having the same problem on linux (ubuntu 22.04) with flutter 3.22.2

Here is a link to my app that demonstrates the problem.

https://github.com/bsutton/handyman/tree/deep_link

the flutter project is in the 'hmb' subdirectory.

clone the branch, open the hmb directory with vs-code and then try and open the deeplink page and run a scan:

image

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.2, on Ubuntu 22.04.4 LTS 6.5.0-41-generic, locale en_AU.UTF-8) [!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/linux#android-setup for more details. [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2023.3) [!] Android Studio (version unknown) ✗ Unable to determine Android Studio version. ✗ android-studio-dir = /home/bsutton/Android/Sdk ✗ Unable to find bundled Java version. [✓] VS Code (version 1.90.2) [✓] Connected device (3 available) [✓] Network resources

! Doctor found issues in 2 categories.

sajjademad commented 2 months ago

I was facing the same problem on mac. Writing the path to my project manually (instead of using the auto detected path by the devTools ) fixed it for me .

bsutton commented 2 months ago

Entering the path manually made no difference to me - the problem persisted.

bsutton commented 2 months ago

I just enable detailed logging on windows and found the following error:

{"level":"FINE","message":"requesting api/androidBuildVariants?rootPath=%2Fc%3A%2FUsers%2Fbsutt%2Fgit%2Fhandyman%2Fhmb%2F","timestamp":"2024-07-13 23:31:31.131Z","loggerName":"devtools_server_client"}
{"level":"WARNING","message":"HttpRequest api/androidBuildVariants failed status = 500, responseText = {\"error\":\"Flutter command exit with non-zero error code 1\\nYou provided the path 'c:\\\\c:\\\\users\\\\bsutt\\\\git\\\\handyman\\\\hmb', however it does not exist on disk\\n\"}","timestamp":"2024-07-13 23:31:31.800Z","loggerName":"devtools_server_client"}
{"level":"FINE","message":"Event: select(screenName:settings, selectedItem:copyLogs, value:0, nonInteraction:false)","timestamp":"2024-07-13 23:31:37.259Z","loggerName":"_analytics_web"}
{"level":"FINE","message":"requesting api/getDevToolsEnabled","timestamp":"2024-07-13 23:31:37.259Z","loggerName":"devtools_server_client"}

So I then manually entered the path:

c:/users/bsutt/git/handyman/hmb

image

and now the deep links validator is working. I doubt this is the problem on linux.

wildsylvan commented 2 months ago

same issue:

image image

inserting the path manually without the leading / fixes it:

image

bsutton commented 2 months ago

I've just had a moment to pull the logs from my linux system:

{"level":"FINE","message":"requesting api/androidBuildVariants?rootPath=%2Fhome%2Fbsutton%2Fgit%2Fhandyman%2Fhmb%2F","timestamp":"2024-07-16 00:38:06.966Z","loggerName":"devtools_server_client"}
{"level":"WARNING","message":"HttpRequest api/androidBuildVariants failed status = 500, responseText = Internal Server Error","timestamp":"2024-07-16 00:38:07.071Z","loggerName":"devtools_server_client"}
{"level":"FINE","message":"Event: select(screenName:settings, selectedItem:copyLogs, value:0, nonInteraction:false)","timestamp":"2024-07-16 00:38:15.639Z","loggerName":"_analytics_web"}
{"level":"FINE","message":"requesting api/getDevToolsEnabled","timestamp":"2024-07-16 00:38:15.639Z","loggerName":"devtools_server_client"}

Edit: I can also successfully run build-variants:

 flutter analyze --android --list-build-variants
Running Gradle task 'printBuildVariants'...                         9.2s
["debug","release","profile"]
Dararii commented 4 weeks ago

Same issue here, any workaround? Flutter 3.24.1 stable and 3.94.0 VSCode extension version.

Update: it does not work when my Path has spaces and replaced by default with '%20'. Instead, if I am using ' ', the problem is gone.

kenzieschmoll commented 3 weeks ago

@DanTup these project roots come from DTD: https://github.com/flutter/devtools/blob/master/packages/devtools_app/lib/src/screens/deep_link_validation/project_root_selection/select_project_view.dart/#L45. Do any recent improvements you made WRT to windows paths affect the issue described here?

DanTup commented 3 weeks ago

@kenzieschmoll I think this is the same issue we've seen elsewhere, calling .path on a file:/// URI:

https://github.com/flutter/devtools/blob/792ba0e10a0e1d4d4154653cd5515b0d0b8cffe8/packages/devtools_app/lib/src/screens/deep_link_validation/project_root_selection/root_selector.dart#L122

For a windows file URI like file:///c:/foo this results in /c:/foo which is not valid (toFilePath() would return c:\foo). Basically, using .path on a File URI is almost never a safe thing to do. For Dart CLI code, toFilePath() is the correct/safe thing to do, however unfortunately things are more complicated when running in the browser, because it always assumes non-Windows.

It's basically the same issue we discussed at https://github.com/flutter/devtools/pull/7116#pullrequestreview-1844297875, however in that case we're going from a path to a URI so we can easily just use the slash direction in the path to decide if it's Windows or not, whereas here we're going in the other direction and have lost that.

Some possible thoughts:

  1. Assume if .path of the file URI starts with /[a-zA-Z]: then it's Windows
  2. We include some flag about whether the paths are Windows or posix when returning the roots from the server (or DTD?)
bishal-rumba007 commented 5 hours ago

I had the same issue: my project is located in F:\Flutter Projects\myapp

here is what I did:

  1. open terminal
  2. run 'dart devtools'
  3. navigate to deep link tab
  4. entered project path manually
    • I am on windows so the path was: F:\Flutter Projects\myapp
    • I typed in /Flutter Projects/myapp

and it worked!