Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't access --dart-define arguments in dart code when run native project in root/android folder with Android Studio #61713

Closed
elanpang opened this issue Jul 17, 2020 · 4 comments
Labels
found in release: 1.21 Found to occur in 1.21 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@elanpang
Copy link

elanpang commented Jul 17, 2020

I have read this article that about --dart-define
Flutter 1.17 — no more Flavors, no more iOS Schemas. Command argument that changes everything

I notice that after running flutter run --dart-define=ENV=QA to launch app on iOS device by Command-Line, in iOS folder a Generated.xcconfig will be generated in xcode project, so next time I can debug app with xcode directly the app can get ENV value through Generated.xcconfig in dart code.
like:
static const appEnv = String.fromEnvironment('ENV', '');

But after running flutter run --dart-define=ENV=QA to launch app on android device by Command-Line, then use Android Studio to open the native project in android root/folder, debug app directly, the app still can't get ENV value, is there any way that let me can debug android app and pass dart-define into app? without vscode or commond-line because I need to debug native code with Android Studio but the command argument is required in dart code.

@elanpang elanpang changed the title can’--dart-define arguments can't access --dart-define arguments in dart code when run native project in root/android folder with Android Studio Jul 17, 2020
@VladyslavBondarenko
Copy link

Reproduces with current master 1.21.0-2.0.pre.55.
Used the project from mentioned article

@VladyslavBondarenko VladyslavBondarenko added found in release: 1.21 Found to occur in 1.21 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Jul 17, 2020
@jonahwilliams
Copy link
Member

This is not a bug - If you want to run through gradle you still need to provide the project args that flutter run would use. You can see these by running flutter run -v - the verbose logs will include the exact command to run

@elanpang
Copy link
Author

elanpang commented Jul 20, 2020

Thanks for your help, found a solution.

flutter run -v can show command details, so I found the android native command is:

gradlew -Pdart-defines=flutter.inspector.structuredErrors=true,ENV=qa ...

-P, --project-prop means set project property for the build script (e.g. -Pmyprop=myvalue).

Then open AndroidStudio > Preferences > Build... > Complier,

added -Pdart-defines=ENV=qa to ComandLineOptions

It works!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 1.21 Found to occur in 1.21 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests

3 participants