Edit 2019-12-13:
As of Flutter 1.12 (stable) released on Dec 11 2019, flutter boilerplate now includes gradle distribution 5.6.2 and plugin version 3.5.0 which will hopefully make this a historical SO question. Plugin version 3.5.3 is current, but even version 3.5.0 should fix the issue as initially reported.
Original answer:
This appears to be caused by the Flutter boilerplate specifying an old version of the gradle plugin. I'm still unclear if Flutter package updates in pubspec.yaml/lock are triggering the issue, I rolled back a way but it was still present here.
For some reason this affects my Windows 10 system, but not my Mac development environment. Both are up-to-date (Flutter 1.7.8+hotfix.4) and on the same versions of everything as far as I'm aware. On account of this Windows path separators are used in the notes below.
In androidgradlewrappergradle-wrapper.properties
the Flutter boilerplate specifies a gradle distribution of 4.10.2, which supports a plugin version of up to 3.3.2. However, androiduild.gradle
only depends on plugin version 3.2.1 (classpath 'com.android.tools.build:gradle:3.2.1'
). It's unclear why the Flutter boilerplate isn't more internally consistent.
To resolve, change com.android.tools.build:gradle:3.2.1
=> com.android.tools.build:gradle:3.3.2
, run flutter clean
and try the build again.
According to the gradle release notes, the current (July 2019) version of the plugin and gradle are 3.4.2 and 5.1.1 respectively. I don't know if Flutter officially supports this version, although it seems to work on my project here and a clean build is markedly faster. The release notes cover some of the changes from 3.2.x => 3.3.x => 3.4.x.
To upgrade to the current version, edit androidgradlewrappergradle-wrapper.properties
to source gradle 5.1.1, and then you're able to upgrade the gradle plugin to 3.4.2.
gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
build.gradle:
classpath 'com.android.tools.build:gradle:3.4.2'
Note that once gradle 5.1.1 is being used, you can still set the plugin version back to 3.2.1 to reproduce the issue.
I've opened an issue with the Flutter team to try and understand this better and will update this answer if they come back with anything concrete.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…