Home > Enterprise >  Android builds twice when using flutter flavours
Android builds twice when using flutter flavours

Time:03-29

I recently upgraded Flutter from 2.2.x to 2.10.x.

All was working fine on 2.2.x. On the new version, iOS works properly, but Android is having issues, as it seems to be running the app build.gradle twice: a first time with the proper flavour, a second time with no flavour.

The command is flutter run --flavor dev

The error I get is:

Launching lib/main.dart on sdk gphone x86 arm in debug mode...
lib/main.dart:1
Reading env from: .env.dev
Starting a Gradle Daemon, 1 busy and 8 stopped Daemons could not be reused, use --status for details
> Configure project :app
Reading env from: .env
**************************
*** Missing .env file ****
**************************
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.2/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/guillaumeferron/Sites/TendoPay-App/android/app/build.gradle' line: 26

* What went wrong:
A problem occurred evaluating project ':app'.
> Cannot invoke method split() on null object

As you can see, there is a double "Reading env from", which should not happen. The first run works fine and goes through, but gets killed by the second run that fails.

The faulty line (which is not the issue itself, but a consequence of the dual run) is: def flutterVersionCode = Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[0]) * 10000 Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[1]) * 100 Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[2])

My flutter doctor is:

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-x64, locale en-CA)
    • Flutter version 2.10.3 at /Users/guillaumeferron/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (3 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 30.0.2)
    • Android SDK at /Users/guillaumeferron/Library/Android/sdk
    • Platform android-31, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
                 
  • Related