Repository navigation
Flutter build fails when using gradle 4.0 #10236
Description
UPDATE:
Happens only when Android Studio is 3.0 and uses Gradle 4.0-milestone-1
I was working on my project for couple of days on my Mac. When I pushed to github to get it on my linux machine it failed to compile. This time I was using Android Studio 3.0 Canary. Problem is in line 20 of android/build.gradle file.
Running 'gradle assembleDebug' directly completes without failure.
Similar issues
com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
were reported for Kotlin and ReactNative plugins.
some suggested problem may be related to case sensitive file systems. Mac isn't case sensitive.
Steps to Reproduce
run flutter run on linux (Ubuntu Gnome)
observe build fails during gradle assembleDebug task
replicable 100%
Logs
[ +79 ms] [/home/swav/Library/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +21 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/alpha
[ ] [/home/swav/Library/flutter/] git ls-remote --get-url origin
[ +13 ms] Exit code 0 from: git ls-remote --get-url origin
[ ] https://github.com/flutter/flutter.git
[ ] [/home/swav/Library/flutter/] git log -n 1 --pretty=format:%H
[ +13 ms] Exit code 0 from: git log -n 1 --pretty=format:%H
[ ] 973304d5fbf737510ecc250b93d9ee2e872b563f
[ ] [/home/swav/Library/flutter/] git log -n 1 --pretty=format:%ar
[ +13 ms] Exit code 0 from: git log -n 1 --pretty=format:%ar
[ ] 2 days ago
[ +210 ms] Listing devices using /home/swav/Android/Sdk/platform-tools/adb
[ ] /home/swav/Android/Sdk/platform-tools/adb devices -l
[ +12 ms] Exit code 0 from: /home/swav/Android/Sdk/platform-tools/adb devices -l
[ ] List of devices attached
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
[ +59 ms] /home/swav/Android/Sdk/platform-tools/adb -s emulator-5554 shell getprop
[+3479 ms] Launching lib/main.dart on Android SDK built for x86 in debug mode...
[ +211 ms] Using gradle from /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle.
[ +10 ms] [android/] /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle app:properties
[ +753 ms] Exit code 1 from: /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle app:properties
[ ] FAILURE: Build failed with an exception.
* Where:
Build file '/home/swav/Git/flutter/status-app/android/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[ ] Error running gradle: Exit code 1 from: /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle app:properties
[ +28 ms] /home/swav/Android/Sdk/platform-tools/adb -s emulator-5554 logcat -v time -t 1
[ +20 ms] Exit code 0 from: /home/swav/Android/Sdk/platform-tools/adb -s emulator-5554 logcat -v time -t 1
[ ] --------- beginning of main
05-20 22:53:19.686 I/DeviceStateChecker( 5077): DeviceStateChecker cancelled
[ +1 ms] /home/swav/Android/Sdk/platform-tools/adb -s emulator-5554 logcat -v time
[ +4 ms] /home/swav/Android/Sdk/platform-tools/adb version
[ +37 ms] Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as /home/swav/Android/Sdk/platform-tools/adb
[ +2 ms] /home/swav/Android/Sdk/platform-tools/adb start-server
[ +203 ms] Building APK
[ +224 ms] Using gradle from /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle.
[ +6 ms] Running 'gradle assembleDebug'...
[ +1 ms] [android/] /home/swav/Library/android-studio-3.0/gradle/gradle-4.0-milestone-1/bin/gradle -Ptarget=/home/swav/Git/flutter/status-app/lib/main.dart assembleDebug
[ +652 ms] FAILURE: Build failed with an exception.
[ ] * Where:
[ ] Build file '/home/swav/Git/flutter/status-app/android/build.gradle' line: 20
[ ] * What went wrong:
[ ] A problem occurred evaluating root project 'android'.
[ ] > A problem occurred configuring project ':app'.
[ ] > Failed to notify project evaluation listener.
[ ] > com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
[ ] * Try:
[ ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[ +4 ms] BUILD FAILED in 0s
[ +366 ms] "flutter run" took 6,247ms.
Gradle build failed: 1
#0 throwToolExit (package:flutter_tools/src/base/common.dart:29)
#1 buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:244)
<asynchronous suspension>
#2 buildGradleProject (package:flutter_tools/src/android/gradle.dart:192)
<asynchronous suspension>
#3 buildApk (package:flutter_tools/src/commands/build_apk.dart:83)
<asynchronous suspension>
#4 AndroidDevice.startApp (package:flutter_tools/src/android/android_device.dart:334)
<asynchronous suspension>
#5 FlutterDevice.runHot (package:flutter_tools/src/resident_runner.dart:223)
<asynchronous suspension>
#6 HotRunner.run (package:flutter_tools/src/run_hot.dart:183)
<asynchronous suspension>
#7 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:321)
<asynchronous suspension>
#8 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:210)
<asynchronous suspension>
#9 RunCommand.verifyThenRunCommand (package:flutter_tools/src/commands/run.dart:210)
<asynchronous suspension>
#10 FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:156)
<asynchronous suspension>
#11 CommandRunner.runCommand (package:args/command_runner.dart:194)
<asynchronous suspension>
#12 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:261)
<asynchronous suspension>
#13 CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:109)
#14 Future.Future.sync (dart:async/future.dart:208)
#15 CommandRunner.run (package:args/command_runner.dart:109)
#16 FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:156)
#17 run.<anonymous closure> (package:flutter_tools/executable.dart:140)
<asynchronous suspension>
#18 AppContext._run (package:flutter_tools/src/base/context.dart:76)
<asynchronous suspension>
#19 AppContext.runInZone.<anonymous closure> (package:flutter_tools/src/base/context.dart:66)
#20 _rootRun (dart:async/zone.dart:1120)
#21 _CustomZone.run (dart:async/zone.dart:1001)
#22 runZoned (dart:async/zone.dart:1465)
#23 AppContext.runInZone (package:flutter_tools/src/base/context.dart:65)
#24 run (package:flutter_tools/executable.dart:113)
<asynchronous suspension>
#25 main (package:flutter_tools/executable.dart:66)
<asynchronous suspension>
#26 main (file:///home/swav/Library/flutter/packages/flutter_tools/bin/flutter_tools.dart:16)
#27 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)
[ +85 ms] ensureAnalyticsSent: 74ms
[ +158 ms] [/tmp/flutter_tools_uHo3u3/] zip -r -q /home/swav/Git/flutter/status-app/bugreport_03.zip .
[ +166 ms] Exit code 0 from: zip -r -q /home/swav/Git/flutter/status-app/bugreport_03.zip .
[ ] Bug report written to bugreport_03.zip.
Note that this bug report contains local paths, device identifiers, and log snippets.
[ +9 ms] exiting with code 1
Flutter Doctor
[✓] Flutter (on Linux, channel alpha)
• Flutter at /home/swav/Library/flutter
• Framework revision 973304d (2 days ago), 2017-05-18 17:31:57 -0700
• Engine revision f99d3ef
• Tools Dart version 1.23.0-dev.11.11
[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
• Android SDK at /home/swav/Android/Sdk
• Platform android-25, build-tools 25.0.3
• Java binary at: /home/swav/Library/android-studio-3.0/jre/bin/java
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b736)
[✓] Android Studio (version 3.0)
• Android Studio at /home/swav/Library/android-studio-3.0
• Gradle version 4.0-milestone-1
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b736)
[✓] Android Studio (version 2.3)
• Android Studio at /home/swav/Library/android-studio-2.3.1
• Gradle version 3.2
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] Connected devices
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
Activity
twotwotwo commentedon May 22, 2017
It's possible the cause here is that Android Studio 3.0 bundles Gradle 4.0, which (from searching around) was scheduled to deprecate the setDependencyCacheDir API, which some plugins might still be written against. If that's it, I'm not sure what exactly you do to get the
fluttertool to talk to the tools installed for Studio 2.3 instead, but that seems like a possible approach.(I'm not writing this as a Flutter expert, just a user that ran into the same message after looking at both Flutter and Studio 3.0 after the recent I/O announcements.)
eseidelGoogle commentedon May 22, 2017
FYI @jakobr-google @jason-simmons.
jakobr-google commentedon May 22, 2017
If you have several versions of Android Studio installed, you can configure which one Flutter Tools uses by running
flutter config --android-studio-dir=<path to Studio>.If you just want to specify which Gradle to use, run
flutter config --gradle-dir=<path to Gradle>.But yeah, we'll need to figure out why we're failing with the latest Gradle, and fix that.
eseidelGoogle commentedon May 24, 2017
We got another report of this just now in Gitter. The workaround (configure flutter to point to an older gradle) works. @jason-simmons started looking at what it would take to use a wrapped gradel yesterday. Unclear if that would help with this bug or not.
dodyg commentedon May 28, 2017
I got the same
flutter createflutter runLaunching lib/main.dart on Android SDK built for x86 in debug mode...edit: I successfully run in from IntelliJ. I am not sure what's the problem with
flutter run. It could be there's some processing going on when it is called, but it's not obvious.ojhariddhish commentedon May 29, 2017
Thanks @jacobr-google. Changing Android Studio version to 2.4 in Flutter config fixed the issue.
[-]flutter run fails on android debugCompile (Linux)[/-][+]Gradle wrapper[/+]asaarnak commentedon Jun 10, 2017
Seems like it's fixed by using newer build tools version:
Currently the flutter create template has older version 2.2.3
because it defaults to Android Studio gradle version, which is gradle 3.2 on latest stable studio 2.3.
[-]Gradle wrapper[/-][+]Flutter build fails when using gradle 4.0[/+]mravn-google commentedon Jun 26, 2017
Update (following #10928):
android/gradle/wrapper/gradle-wrapper.propertiesto target Gradle 3.5 or Gradle 4.0 has also been tested to work in both scenarios.android/gradle/wrapper/gradle-wrapper.propertiesto target Gradle 3.5 or later, and thenHixie commentedon Jan 8, 2018
I just hit this trying to run the Flutter apps in the assets-for-api-docs repo, presumably because those are way out of date. We really need to have a way to upgrade people...
Hixie commentedon Jan 8, 2018
(Deleting the android/ directory and recreating it with
flutter createfixed it.)jasdeepsingh commentedon Jan 27, 2018
I'm having the same issue with:
And Android Studio 3.0
charafau commentedon Mar 17, 2018
android needs
3.0.1version of gradle plugin to build with gradle >= 4.1davidair commentedon Apr 15, 2018
Running into this with Android Studio 3.1.1, gradle 4.4 and com.android.tools.build:gradle:3.1.1. I'm able to run for release (flutter run --release) but not debug. I only have one (latest) version of Android Studio installed. Is there a workaround for this?
mravn-google commentedon Apr 15, 2018
@davidair Flutter tooling creates Flutter projects based on an Android Studio 3.0.1/Gradle 4.1 template. We'll update that once the dust of Android Studio 3.1.x settles. If you want to be using a newer Android Studio/Gradle configuration already now, you need to change
android/build.gradleandandroid/gradle/wrapper/gradle-wrapper.propertiesaccordingly in your Flutter project files. Android Studio 3.1.1 will offer to do that for you, if you open theandroid/folder of a newly created Flutter project.If the above does not work for you, please file a new issue detailing the output of
flutter doctor -v, your currentbuild.gradlefiles, and the error output that you get from runningflutter run -v. As an example, if I try to use the Gradle plugin of Android Studio 3.1.1 with Gradle 4.1 (so updatingandroid/build.gradle, but notandroid/gradle/wrapper/gradle-wrapper.properties), I get the following:davidair commentedon Apr 15, 2018
The way I got into this situation was to create my Flutter project on my Mac and then attempt running it on Windows. Both Mac and Windows run Android Studio 3.1.1, but the output of
flutter --versionlooks different:Mac
Flutter 0.0.22-pre.1 • channel alpha • https://github.com/flutter/flutter.git Framework • revision 553fc4264e (6 weeks ago) • 2018-03-01 09:30:25 -0800 Engine • revision 6921873c71 Tools • Dart 2.0.0-dev.16.0Windows
Flutter • channel alpha • https://github.com/flutter/flutter.git Framework • revision e8aa40eddd (6 months ago) • 2017-10-17 15:42:40 -0700 Engine • revision 7c4142808c Tools • Dart 1.25.0-dev.11.0When I create a new project on Mac, it uses the following settings:
When I create a new project on Windows, it uses the following settings:
The later works - so I ended up downgrading the gradle files in my project and it now runs on my physical Android device both on Windows and Mac.
Note that attempting to manually roll forward to Gradle 4.4 and com.android.tools.build:gradle:3.1.1 on Windows didn't work
mit-mit commentedon Apr 16, 2018
@davidair those are very old flutter framework builds! I recommend you switch to the beta channel (run the command
flutter channel beta), and then upgrade (run the commandflutter upgrade).davidair commentedon Apr 17, 2018
I upgraded flutter on both machines (was a bit of a mess on Windows because it was so old) and I was able to run a project using 3.1.1 plugin on my Windows box. Thanks for the tip!
Note: I'm surprised "flutter doctor" didn't tell me anything about running an old version.
ffeu commentedon Apr 21, 2018
I was having the same issues and upgrading both flutter and android studio didn't do it. I guess the problem happens once you're stuck with an old project and the tools get updates.
What got it right was updating:
I used the latest sdk and buildtools versions I've found in the folders .../sdk/build-tools and .../sdk/platforms.
rakz25 commentedon Aug 7, 2018
my grade.build file is below:
buildscript {
repositories {
google()
jcenter()
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Still have the same issue:
line: 20
A problem occurred evaluating root project 'android'.
ffeu commentedon Aug 7, 2018
I recommend you create a new project and transfer your files to the new one.
As flutter evolves, some of its improvements end up leaving old projects stuck.
I have even created a script for that, it copies the lib/, assets/, icons/*, pubspec.yaml, etc..
github-actions commentedon Sep 2, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.