3

I've seen a few issues similar on Stack overflow, but not one that quite relates to the same libraries.

I'm trying to use 2 plugins in flutter flutter_geofence and geolocator

They've both been working fine, but since yesterday as soon as of the location play services are called I'm getting the app quit with a stack trace similar to below:

E/flutter (11478): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(39)] java.lang.NoSuchMethodError: No static method isAtLeastR()Z in class Landroidx/core/os/BuildCompat; or its super classes (declaration of 'androidx.core.os.BuildCompat' appears in /data/app/com.mypossibleself.app-FTu9V5QDAKR_ngQmuPzg7Q==/base.apk!classes2.dex)
E/flutter (11478):  at com.google.android.gms.common.util.PlatformVersion.isAtLeastR(com.google.android.gms:play-services-basement@@17.2.1:21)
E/flutter (11478):  at com.google.android.gms.common.api.GoogleApi.zaa(com.google.android.gms:play-services-base@@17.2.1:128)
E/flutter (11478):  at com.google.android.gms.common.api.GoogleApi.<init>(com.google.android.gms:play-services-base@@17.2.1:41)
E/flutter (11478):  at com.google.android.gms.common.api.GoogleApi.<init>(com.google.android.gms:play-services-base@@17.2.1:56)
E/flutter (11478):  at com.google.android.gms.location.FusedLocationProviderClient.<init>(Unknown Source:8)
E/flutter (11478):  at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source:2)
E/flutter (11478):  at com.baseflow.geolocator.tasks.LocationUpdatesUsingLocationServicesTask.<init>(LocationUpdatesUsingLocationServicesTask.java:29)
E/flutter (11478):  at com.baseflow.geolocator.tasks.TaskFactory.createStreamLocationUpdatesTask(TaskFactory.java:120)
E/flutter (11478):  at com.baseflow.geolocator.GeolocatorPlugin.onListen(GeolocatorPlugin.java:110)
E/flutter (11478):  at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:193)
E/flutter (11478):  at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:172)
E/flutter (11478):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/flutter (11478):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/flutter (11478):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (11478):  at android.os.MessageQueue.next(MessageQueue.java:336)
E/flutter (11478):  at android.os.Looper.loop(Looper.java:174)
E/flutter (11478):  at android.app.ActivityThread.main(ActivityThread.java:7356)
E/flutter (11478):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (11478):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/flutter (11478):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

So it's complaining about a missing method isAtLeastR

Other references I've seen to this mention specific versions of com.google.android.gms:play-services-base causing this, but that it's fixed in com.google.android.gms:play-services-base:17.2.1

Neither of these library implement that package in their build.gradle files so I'm at a loss as to what needs doing to fix this issue.

Andrew
  • 7,548
  • 7
  • 50
  • 72
  • So your app/build.gradle has ` com.google.android.gms:play-services-base:17.2.1` in it? Did you do flutter clean before running? – Adelina Apr 02 '20 at 13:22
  • Yep, I've spent over 24 hours on this. I've done a clean. We don't directly access com.google.android.gms:play-services-base in our app/build.gradle at all. Do you think it'd help if we did? It'll be coming from a library I'd guess – Andrew Apr 02 '20 at 14:21

2 Answers2

4

In the app/build.gradle add com.google.android.gms:play-services-base:17.2.1 this should make libraries use specific version of play-services.

If it doesn't help, might need to

configurations.all {
    resolutionStrategy {
        force 'com.google.needed_dependency'
    }
}

https://flutter.dev/docs/development/packages-and-plugins/using-packages#conflict-resolution

Edit as per Andrews suggestion:

17.2.1 doesn't work, but 17.0.0 does.

implementation("com.google.android.gms:play-services-base:17.0.0"){ force = true } 
Adelina
  • 10,915
  • 1
  • 38
  • 46
  • 1
    I've ended up with something slightly different, but you pointed me in the right direction. 17.2.1 doesn't work for me but 17.0.0 does. I've also ended up going for this definition. implementation("com.google.android.gms:play-services-base:17.0.0"){ force = true } – Andrew Apr 02 '20 at 14:56
  • 1
    I will update the answer with your comment. Thanks for letting me know – Adelina Apr 02 '20 at 14:58
  • @Andrew where exactly did you add this line? – Niklas Raab Apr 16 '20 at 20:56
  • For reference....Similar issue using Firebase plugins. 17.2.1 didn't work but 17.1 did with force. However given this is a few months later 17.3.0 is available and fixed it. – plam Jun 20 '20 at 00:57
0
resolutionStrategy {
            force 'com.google.android.gms:play-services-base:17.1.0' 
        }           
}

This is what solved it for me.

Niklas Raab
  • 1,576
  • 1
  • 16
  • 32