Appearance
(This wiki page applies to people migrating code written before December 2017. It is unlikely to still be relevant.)
Introduction
Prior to #13492 (merged on 2017-12-13), Flutter tooling created projects whose Android part used Gradle 3.3 and the Android Studio Gradle plugin version 2.3.3.
After #13492, Flutter tooling creates projects based on Gradle 4.1 and the Android Studio Gradle plugin version 3.0.1.
This page describes how you can manually upgrade your Flutter projects from the old mode to the new one. This may be needed to consume new-mode Flutter plugins.
Where in doubt, please consult https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html.
Upgrading a Flutter app project
In
android/gradle/wrapper/gradle-wrapper.properties
, replace3.3
with4.1
in the last line.In
android/build.gradle
, replacegradlerepositories { jcenter() maven { url "https://maven.google.com" } }
by
gradlerepositories { google() jcenter() }
twice.
Also replace
gradledependencies { classpath 'com.android.tools.build:gradle:2.3.3' }
by
gradledependencies { classpath 'com.android.tools.build:gradle:3.0.1' }
Finally, replace
gradlesubprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app') }
by
gradlesubprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') }
This change prevents a "Gradle build failed to produce an Android package" error message when your app depends on plugins whose name comes before "app" in lexicographic order.
In
android/app/build.gradle
, replace version25
by27
and25.0.3
by27.0.3
(three places total).If you are using a version of Flutter from before #13558, add the following to the
android
,buildTypes
section:yamlprofile { matchingFallbacks = ['debug', 'release'] }
Replace configurations named
compile
byapi
(orimplementation
) andprovided
bycompileOnly
in thedependencies
section. You may also want to update dependencies with newer versions as applicable. In the default project templates generated by Flutter tooling we have replacedgradledependencies { androidTestCompile 'com.android.support:support-annotations:25.4.0' androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:rules:0.5' }
by
gradledependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' }
loosely following the lead of Android Studio.
Upgrading a Flutter plugin project
Upgrade the
example/
Flutter app project as indicated above.Remove the Gradle wrapper files and folder (
gradlew
,gradlew.bat
,gradle/
) from the top-levelandroid
folder, if present. The Gradle wrapper is used by theexample
app only, and it should already contain these files.In
android/build.gradle
, replacegradlerepositories { jcenter() maven { url "https://maven.google.com" } }
by
gradlerepositories { google() jcenter() }
twice.
Also replace
gradledependencies { classpath 'com.android.tools.build:gradle:2.3.3' }
by
gradledependencies { classpath 'com.android.tools.build:gradle:3.0.1' }
Replace version
25
by27
and25.0.3
by27.0.3
.Lastly, replace configurations named
compile
byapi
(orimplementation
) andprovided
bycompileOnly
in any customdependencies
section.