Upgrading Flutter projects to Gradle 4.1 and Android Studio Gradle plugin 3.0.1
(This wiki page applies to people migrating code written before December 2017. It is unlikely to still be relevant.)
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.
-
In
android/gradle/wrapper/gradle-wrapper.properties
, replace3.3
with4.1
in the last line. -
In
android/build.gradle
, replacerepositories { jcenter() maven { url "https://maven.google.com" } }
by
repositories { google() jcenter() }
twice.
Also replace
dependencies { classpath 'com.android.tools.build:gradle:2.3.3' }
by
dependencies { classpath 'com.android.tools.build:gradle:3.0.1' }
Finally, replace
subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app') }
by
subprojects { 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:profile { 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 replaceddependencies { 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
dependencies { 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.
-
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
, replacerepositories { jcenter() maven { url "https://maven.google.com" } }
by
repositories { google() jcenter() }
twice.
Also replace
dependencies { classpath 'com.android.tools.build:gradle:2.3.3' }
by
dependencies { 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.
- Home of the Wiki
- Roadmap
- API Reference (stable)
- API Reference (main)
- Glossary
- Contributor Guide
- Chat on Discord
- Design documents
- Code of Conduct
- Issue triage reports (latest)
- Our Values
- Tree hygiene
- Issue hygiene and Triage
- Style guide for Flutter repo
- Project teams
- Contributor access
- What should I work on?
- Popular issues
- Running and writing tests
- Release process
- Flutter Framework Gardener Rotation
- Rolling Dart
- Manual Engine Roll with Breaking Commits
- Updating Material Design Fonts & Icons
- Postmortems and Retrospectives
- Hotfix Documentation Best Practices
- In case of emergency
- Landing Changes With Autosubmit
- Setting up the Framework development environment
- The Framework architecture
- API Docs code block generation
- Running examples
- Using the Dart analyzer
- The flutter run variants
- Test coverage for package:flutter
- Writing a golden-file test for package:flutter
- Managing template image assets
- Setting up the Engine development environment
- Compiling the engine
- Debugging the engine
- Using Sanitizers with the Flutter Engine
- Testing the engine
- The Engine architecture
- Flutter's modes
- Crashes
- more...
- Setting up the Packages development environment
- Plugins and Packages repository structure
- Contributing to Plugins and Packages
- Understanding Packages tests
- Plugin Tests
- Releasing a Plugin or Package
- more...