Getting Error With geolocator: ^3.0.0 in flutter if i add in pubspec.yaml file, not able to build android app

47
February 16, 2019, at 7:00 PM

If I add geolocator: ^3.0.0 in pubspec.yaml file in Flutter my Android app not able to build and throwing an error like:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

I have tried changing the target and buildtool version from 27 to 28 still getting same issue

build.gradle file.

android {
    compileSdkVersion 28
    dexOptions {
        javaMaxHeapSize "4g"
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        multiDexEnabled true
        applicationId "com.depl.toours.business"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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
        }
    }
}

main.dart file.

  class MyDemoPage extends State<AccommodationPage> {
        @override
              void initState() {
                super.initState();
                propertyList = new List<String>();
                propertyList.add('Hotel');
                propertyList.add('Gust House');
                _getCurrentPosition();
              }
              _getCurrentPosition() async{
                GeolocationStatus status = await Geolocator().checkGeolocationPermissionStatus(locationPermission: GeolocationPermission.location);
                print('GPS: $status');
               Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
               double lat = position.latitude;
               double lng = position.longitude;
               print('LatLng: ${lat} & ${lng}');
              }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text('Accommodation'),
      ),
      body: _getBody(),
    );
  }
    }

Am expecting current location co-ordinates from the geolocator: ^3.0.0 package and also included multidexEnabled true in defaultConfig (build.gradle file).

Answer 1

I think you either need to use

android {
    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

In your setup this is missing

        minSdkVersion 21
        targetSdkVersion 28

or if you need to support min SDK < 21

android {
    defaultConfig {
        ...
        minSdkVersion 15
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}
dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

In your setup this is missing

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

For more details see https://developer.android.com/studio/build/multidex

READ ALSO
MismatchSenderId error Firebase Cloud Messaging (FCM)

MismatchSenderId error Firebase Cloud Messaging (FCM)

I have been facing this error for days, I have read almost every question on this topic, but I haven't figured out the solution

69
What does prototype scope mean in android?

What does prototype scope mean in android?

Recently I appeared for an interview where he asked me this questionI have never came across such concept in android

44
android Swipe completely hidden view up and down with bottomsheet or viewdraghelper

android Swipe completely hidden view up and down with bottomsheet or viewdraghelper

In my android app I need to create a view that user can slide up and down with fingerNot just slide up/down with swipe/fling but slide up/down when finger is held down on screen

28