0

Whenever I'm trying to include flutter geolocation(https://github.com/loup-v/geolocation) plugin I'm getting following error.

Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

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

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

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

My pubspec.yml dependancies list is

dependencies:
  flutter:
    sdk: flutter
  google_sign_in: "^3.0.2"
  firebase_auth: "^0.5.5"
  shared_preferences: "^0.4.1"
  cloud_firestore: "^0.7.2"
  firebase_storage: "^0.2.5"
  image_picker: "^0.4.1"
  progress_hud: "^0.2.2"
  cached_network_image: "^0.4.1"
  intl: "^0.15.6"
  path: "^1.5.1"
  geolocation: "^0.2.1"

My app>build.gradle code

def localProperties = new Properties()
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.")
}

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.bhramaan.bhramaan"
        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 {
    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'
}

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

What's going wrong?

2
  • github.com/flutter/flutter/issues/14874 might have suggestions Commented Jun 7, 2018 at 18:11
  • @GünterZöchbauer I've already checked that also. But, till now no luck. Commented Jun 11, 2018 at 17:17

4 Answers 4

3

There are three things I can suggest to help. The first is to do a full rebuild by first running flutter clean and then running again. Occasionally things get a little bit messed up between flutter & android, and that helps.

The next thing I would do is check that you're getting the same version of all the Play services. For some reason gradlew sometimes messes that up. Run gradlew app:dependencies from the android (or ./gradlew if you're on mac/linux). If you're getting different versions, add them all as dependencies of the same version.

For example, in my android/app/build.gradle, I had to set

implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation 'com.google.android.gms:play-services-vision:15.0.2'

even though Gradle should have sorted that out. In particular look out for com.google.android.gms:play-services-location as it's a dependency of the geolocation package. Same goes for the com.android.support libraries.

If that still doesn't work, try running the gradle build directly, and in particular looking at the stack trace (gradlew app:build --stacktrace from the android folder) to see if it tells you anything. You could then post that, or take a look at the generic Android questions for a solution. It could be that you need to enabler multi-dex, although I don't think so.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this info. But, not super acquainted with all these level of android configuration stuff. I tried flutter clean. But, that didn't work. Tried to run those gradlew app:dependencies & ./gradlew commands but those also didn't work. Maybe I need to install Gradle on my system. But Gradle website seems down from yesterday. I've posted my app>build.gradle file in my post. Is there anything wrong in that, which may be causing this issue.
1

I believe this is an issue with geolocation gradle version of firebase and your flutter version being incompatible. Try adding multiDexEnabled true to your build gradle. If that does not solve it open your flutters android project in android studio and go to the geolocation build gradle and change dependencies version to classpath 'com.android.tools.build:gradle:3.1.2' & at the bottom update the play services to api "com.google.android.gms:play-services-location:15.+".

Comments

1

Finally, I've fixed this by following the steps as mentioned by @rmtmckenzie.

In my android/app/build.gradle I added following piece of code &

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-location:15.0.1'
    }
}

and enabled multiDexEnabled true

defaultConfig {
    multiDexEnabled true
}

With this setting now, my whole app working fine.

Comments

0

In your app's top level build.gradle update classpath. For me classpath 'com.android.tools.build:gradle:3.5.3' is working fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.