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("\\.")) * 10000 + Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")) * 100 + Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\."))
My flutter doctor is:
I’ve been looking around for a couple hours now, to no avail.
Flutter 2.10.x is not the problem itself, it is Android SDK 31 that is. Indeed, this only happens when I change the SDK version, unfortunately it is a required change in order to support the pub packages versions for 2.10.x.
If I println the different env variables I would get when having it as
APP_VERSION_ANDROID="0.2.3" for instance, would be the first occurrence "0.2.3", and
null the second, which triggers the error.
I have done all the flutter clean, flutter pub get, flutter pub upgrade, gradle clean, etc..
Any help would be appreciated, as I did not find anything relevant online, and lack the Android dev expertise to debug it myself.
Note: the flavour infrastructure I went for is https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b
For anyone stumbling upon this, after many hours of testing and research, what fixed it was to properly upgrade the Android version. So make sure that:
- You open the project with Android Studio, and have all proper grade versions downloaded by going to File > Project Structure. Gradle should be v6.1.1 and Plugin v4.0.1
- Set your kitten version to v1.5.31 (https://docs.flutter.dev/release/breaking-changes/kotlin-version)
- Have both your target and compile sdk version to 31
This should then work properly, and the gradle won’t be executed a second time with no flavor.
Answered By – Guillaume Ferron
Answer Checked By – Cary Denson (FlutterFixes Admin)