Search code examples
flutterdartgeolocator

Flutter geolocator checkDebugDuplicateClasses issue


I have a problem with adding the geolocator (v 11.0.0) Flutter package to my existing project. As soon as I add it to the pubspec.yaml file I get an error FAILURE: Build failed with an exception. Execution failed for task ':app:checkDebugDuplicateClasses'.

To try and test if the problem is in my project specifically or the geolocator package, I created an empty new project (see below main.dart and pubspec.yaml code).

The new (empty) project runs (debugs) normally. But if I uncomment the #geolocator: ^11.0.0 line in pubspec I get the beforementioned error.

main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(
    const MaterialApp(
      home: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Geolocator test"),
      ),
      body: const Center(
        child: Text("Hello"),
      ),
    );
  }
}

pubspec.yaml

name: geolocator_test
description: "A new Flutter project."

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.3.1 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.6
  #geolocator: ^11.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

What am I doing wrong?

environment: Windows 11 Professional, Android Studio Hedgehog 2023.1.1, Flutter 3.19.3, Dart SDK 3.3.1, debugging on Pixel 7 API 31 virtual device.


Solution

  • Had this same issue. What worked for me was adding this to my android/app/build.gradle file:

    configurations.all {
    resolutionStrategy {
        eachDependency {
            if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) {
                useVersion("1.8.0")
            }
        }
    }
    

    }

    Just switch the useVersion("X.X.X") with whatever you need