112

I'm new to Flutter and trying to run the example project when you create a new one. When trying to run it, I have this issue:

FAILURE: Build failed with an exception.

I understand it's trying to get the file "lint-gradle-api-26.1.2.jar" from the jcenter repository but when following the link I get this:

{
  "errors" : [ {
    "status" : 404,
    "message" : "Could not find resource"
  } ]
}

So I added the Google repository in my build.gradle file:

buildscript {
    repositories {
        maven { url 'https://dl.google.com/' }
        google()
        jcenter()
    }

...and I also succeed to get the file by following this link:

https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar

...but I'm still getting the same error when trying to run my project, whether it is by using Visual Studio Code, Android Studio or with the CLI.

How do I force Gradle to download the file from the link I've found?

Here's how my build.gradle file looks like:

buildscript {
    repositories {
        //maven { url 'https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar' }
        repositories {
            google()
            maven { url 'https://maven.fabric.io/public' }
            mavenCentral()
            jcenter()
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        google()
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
        jcenter()
    }
}

repositories {
    google()
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
    jcenter()
}

....
palmtreesnative
  • 2,835
  • 3
  • 14
  • 22

15 Answers15

133

I solved the problem by moving:

maven {
    url 'https://dl.google.com/dl/android/maven2'
}

in the top of:

jcenter()

in the file: .flutter/packages/flutter_tools/gradle/flutter.gradle:

    buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
palmtreesnative
  • 2,835
  • 3
  • 14
  • 22
44

Modify flutter.gradle under ./flutter/packages/flutter_tools/gradle to upgrade the tools version to 3.2.1 and add google() to the first line:

buildscript {
  repositories {
    google()
    jcenter()
    maven {
      url 'https://dl.google.com/dl/android/maven'
    }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
  }
}

Screenshot of my code

Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
mano233
  • 441
  • 4
  • 2
  • Upgrade your flutter, This is my environmental information and I am working now. [√] Flutter (Channel beta, v0.9.4, on Microsoft Windows [Version 10.0.17763.104], locale zh-CN) [√] Android toolchain - develop for Android devices (Android SDK 28.0.3) [√] Android Studio (version 3.2) [√] Connected device (1 available) – mano233 Oct 23 '18 at 10:17
  • 2
    Upgrade distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip – mano233 Oct 23 '18 at 10:21
21

Regarding this error, I just changed this line in the build.gradle file:

classpath 'com.android.tools.build:gradle:3.1.2'

to:

classpath 'com.android.tools.build:gradle:3.1.3'

And that solved my problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alfredo Zamudio
  • 408
  • 3
  • 12
16

This is just a bug in the Gradle file located at C:\flutter\packages\flutter_tools\gradle\flutter.gradle at line 25.

All you have to do is just edit this file by moving it to the top:

maven {
    url 'https://dl.google.com/dl/android/maven2'
}

Change from this

buildscript {
    repositories {

        jcenter()
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

to this:

buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
        jcenter()
    }
    dependencies {`enter code here`
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Charles
  • 1,844
  • 1
  • 14
  • 21
7

This is related to Flutter 0.9.4 at the moment. It will be fixed in the next release. In the meantime, you can update Flutter manually by running the commands described in "Flutter Upgrade". Basically they involve the following:

  1. Change the Flutter GitHub channel to master by running on the command prompt:

    flutter channel master
    
  2. Upgrade Flutter itself by running

    flutter upgrade
    

Once the upgrade is done, run the test drive application, and it should compile successfully.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3399299
  • 569
  • 1
  • 4
  • 4
  • You don't actually need to update the project dependencies repositories, so this answer is the one! :-D – cesards Nov 03 '18 at 17:43
4

Solution:

Put
maven {
    url 'https://dl.google.com/dl/android/maven2'
}
at the top of:
jcenter()

in the file: .flutter/packages/flutter_tools/gradle/flutter.gradle : The file is in the Flutter SDK.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aegon
  • 125
  • 1
  • 4
  • HII Aegon. I didn't find any flutter SDK. Where to find it. I have the same error? – vijju Nov 12 '18 at 06:55
  • You have to download the SDK first, here is a doc explains installation. https://flutter.io/docs/get-started/install – Aegon Nov 12 '18 at 11:22
3

this fixed my issue,SO reference here:

In your root build.gradle make sure google() is before jcenter().

repositories {
    google()
    jcenter()
}

In most projects you will have to update this at 2 spots.

buildscript {
    repositories {
        google()
        jcenter()
    }

}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
Muahmmad Tayyib
  • 689
  • 11
  • 28
2

All the previous answers resolve the problem. One comment to add is the location of the flutte.gradle.

You will find it in the directory that you installed Flutter in for the first time and not on the Flutter project.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mohamed Dernoun
  • 776
  • 5
  • 13
2

Flutter Master Upgrade

I just had this problem. The fix for me however was a lot simpler. After switching branches to dev and upgrading, I switched back to master and it worked perfectly fine.

flutter checkout dev
flutter upgrade

Then switch back

flutter checkout master
flutter upgrade
flutter run
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tdmiller
  • 2,102
  • 2
  • 13
  • 28
2

Just try to upgrade Flutter using the following:

flutter upgrade 

(This issue has been fixed in the latest update.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niyas Ali
  • 203
  • 2
  • 9
1

I also newbie in flutter and just installed it today. And I found the same problem as you, but after three hours googling I finally solved it.

The steps I have done are as follows:

  1. Copy "flutter.gradle" file from "https://github.com/flutter/flutter/blob/master/packages/flutter_tools/gradle/flutter.gradle" into "C:\flutter\packages\gradle"

  2. Then modify the content, for this part:

    buildscript {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }
    

    to:

    buildscript {
        repositories {
            maven {
                    url 'https://dl.google.com/dl/android/maven2'
            }
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }
    
  3. In "c:\flutter\bin", run this command:

    flutter channel master
    

    Wait until finished, and then run this command:

    flutter upgrade
    
  4. Wait until it finished, then re-run the project to debug,

  5. and finally the application appeared on the emulator screen.

    Picture finally running

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mang Ndie
  • 278
  • 3
  • 6
1

For me, opening the gradle-wrapper.properties file and editing the below line like this version solved it:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kogorou
  • 321
  • 3
  • 5
1

When I encountered this error Flutter 1.0 had been released. The previous issues were fixed and still I was getting the same error.

The following steps fixed it for me :

1) Changing Gradle plugin version from 3.1.2 to 3.2.1 in your_project/android/build.gradle inside 'dependencies' section -

dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }

2) Changing Gradle wrapper version from 4.4 to 4.6 in your_project/android/gradle/wrapper/gradle-wrapper.properties like so

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Harisewak
  • 570
  • 6
  • 15
  • Actually, changing Gradle plugin version from "3.2.1" to "3.1.2" worked for me! What's going on here? – Shamshun May 14 '19 at 06:49
1

I have fix just by replacing these sentences:

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'

        }
    }
}

instead of these:

allprojects {
    repositories {
        jcenter()
        google()
    }
}

in build.gradle file and then replace compile with implementation in dependencies

Mohsen Hrt
  • 263
  • 2
  • 9
0

I have fix it with update version build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        ..............
}
Triệu Đô La
  • 2,471
  • 1
  • 9
  • 6