10

I'm a newbie to both Android Studio and Flutter. I recently wanted to try Flutter and hence installed the plugin in Android Studio. My Flutter code has no bugs, but the gradle fails.

app level build gradle:

def localProperties = new Properties()  //here, Properties gets highlighted as error
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")        //here,GradleException gets highlighted as error
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.mee.createevent"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    compile 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-analytics:16.0.1'
    implementation 'com.google.firebase:firebase-analytics:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.2'
    implementation 'com.google.firebase:firebase-functions:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}


apply plugin: 'com.google.gms.google-services'

module level build gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

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
}

My error:

FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.1,16.0.1]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s
Finished with error: Gradle build failed: 1

I've tried including some dependencies such as the play-service version and the firebase analytics versions, but this error doesn't perish and the Properties and GradleException remain highlighted in red as errors.I don't understand how to solve this problem.

pubspec.yaml

name: create_event
description: A new Flutter application.

dependencies:
  cloud_firestore:

  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.io/custom-fonts/#from-packages

When I open app level build gradle image flutter (It says it cannot resolve Properties() and FileNotFoundException() )

But, the same set of errors are resolved and gradle sync is successful when I click the "Open for editing in Android Studio" image androidStudio

But,this success in Android Studio case, doesn't reflect in the Flutter one. It still has those errors.

5
  • Given the failure you pasted, I would suggest reading this link. It is also relevant to Android projects. docs.gradle.org/current/dsl/… Commented Jul 12, 2018 at 4:56
  • The error shows dependency issues, but other things like the Properties() and FileNotFoundException() are being highlighted as errors in the actual code (I've just now attached that image where they are highlighted)
    – Aivi
    Commented Jul 12, 2018 at 13:15
  • I'm honestly not very familiar with Flutter apps. Is the Properties required? Try putting it in your root build.gradle. Also, don't take IDE highlighting too seriously. The important thing is what happens when you try to build. I would definitely suggest resolving all BUILD errors and see where that gets you. Commented Jul 12, 2018 at 14:17
  • You were right, that highlight didn't matter. Thx :)
    – Aivi
    Commented Jul 12, 2018 at 17:21
  • Glad to hear it! It's just a limitation of the tooling (your IDE) in this case. I have "red" code in my build.gradle too, but everything builds just fine, so I have a comment "DON'T DELETE THIS!!!!" :) Commented Jul 12, 2018 at 18:38

6 Answers 6

3

Have you tried adding the google maven repository to your project level build.gradle file?

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

either the buildscript section or the allprojects section.

4
  • Have you tried downgrading your dependencies? Also taking some out until you figure out which one is giving you the errors
    – Serl
    Commented Jul 12, 2018 at 14:20
  • Yess, that absolutely works, thxx :) Using a uniform version like 15.0.2 resulted in improper sync. I used '+' as another friend suggested and finally resolved the issue
    – Aivi
    Commented Jul 12, 2018 at 17:23
  • How can I close this question?
    – Aivi
    Commented Jul 12, 2018 at 17:23
  • 1
    @Aivi This explains it pretty well: link
    – Serl
    Commented Jul 12, 2018 at 18:06
3

When i got this same problem, the only way that i can find to solution it was update gradle versions:

in android/gradle/wrapper/gradle-wrapper.properties

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

and

in android/build.gradle

to dependencies { classpath 'com.android.tools.build:gradle:3.5.3' classpath 'com.google.gms:google-services:4.3.2'

and in android/build.gradle yet

buildscript {
    ext.kotlin_version = '1.3.61'

in pubspec.yaml

firebase_core: ^0.4.2+1 
  cloud_firestore: ^0.12.11

I hope that it can help you.

0

Use only this dependencies in android/build.gradle and remove any other dependencies

classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1' 

And in pubspec.yaml use only these versions to avoid gradle errors:

cloud_firestore: 0.7.3 
firebase_admob: 0.5.5
firebase_auth: 0.5.11
google_sign_in: 3.0.4
firebase_analytic: 1.0.1
firebase_core: 0.2.4 
firebase_database: 1.0.1 
firebase_dynamic_links: 0.02
firebase_messaging: 1.0.2
firebase_performance: 0.0.3
firebase_remote_config: 0.0.4
firebase_storage: 0.3.7
0

I created another app and Replaced all the .dart file and pubspec.yaml. It is the fastest method I found.

0

Change classpath 'com.google.gms:google-services:4.3.2' to classpath 'com.google.gms:google-services:4.2.0'

0

This error can be removed in a following steps:

  1. If possible increase you min sdk version in your project>>android>>app>>build.gradle file 2.Then add a following line in project>>android>>app>>build.gradle dependencies{

implementation 'androidx.multidex:multidex:2.0.1'

} I hope your problem is now solved.

Not the answer you're looking for? Browse other questions tagged or ask your own question.