Skip to content

[Document] Usage of Dart-Define variables in gradle scripts #100292

@Sese-Schneider

Description

@Sese-Schneider

While creating integration tests for our Flutter application, we're facing a blocking issue:

Following the official flutter documentation for integration testing, in the section to automate the tests on Firebase Test Lab, its stated to build the app with gradle.

pushd android
# flutter build generates files in android/ for building the app
flutter build apk
./gradlew app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=integration_test/<name>_test.dart
popd

Unfortuantely, its not stated on how to include --dart-define variables into the script so that the created APK is build with the variable defined.

According to a stackoverflow thread, I've tried setting the variable in gradle.properties, with no effect.

As nothing in this matter is documented, I assume its not possible and therefor file this issue.
If it is possible, how can we pass the dart-define to the gradle build? Adjusting the documentation here might be helpful :)

Expected results:
Integration testable APK with a dart-define variable modified in its source code.

Actual results:
The APK only has default behavior, the variable can't be modified.

Logs
[✓] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.22000.556], locale de-DE)
    • Flutter version 2.10.3 at X:\Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (2 weeks ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at X:\SDK
    • Platform android-31, build-tools 31.0.0
    • Java binary at: X:\JetBrains\apps\AndroidStudio\ch-0\211.7628.21.2111.8193401\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    • All Android licenses accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectdependency: dartDart team may need to help ust: gradle"flutter build" and "flutter run" on AndroidtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions