React-native-geolocation-service: Device Crash on Startup

Created on 10 Aug 2018  路  11Comments  路  Source: Agontuk/react-native-geolocation-service

FATAL EXCEPTION: Thread-6
08-10 07:47:38.939 24097 24137 E AndroidRuntime: Process: com.pack, PID: 24097
08-10 07:47:38.939 24097 24137 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.google.android.gms.location.LocationServices.<clinit>(Unknown Source)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.agontuk.RNFusedLocation.RNFusedLocationModule.<init>(RNFusedLocationModule.java:96)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.agontuk.RNFusedLocation.RNFusedLocationPackage.createNativeModules(RNFusedLocationPackage.java:26)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:106)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1191)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1161)
08-10 07:47:38.939 24097 24137 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1094)

ANy idea how to solve this? I suspect this is because I am somehow using other versions of the google services library.. but i could use some guidance as to why this happens

Most helpful comment

this work for me

  1. in root "build.gradle" add below code

ext {
googlePlayServicesVersion = "11.0.0"
}

  1. in "app/build.gradle"

dependencies {
...
implementation "com.google.android.gms:play-services-location:16.0.0" // <-- add this line
}

All 11 comments

You are using libraries that depend on some google play service modules, and each library is using different versions of google play service. You have to make sure all libraries use the same version, even if they're using different modules. You can check the dependencies by using the cd android && ./gradlew app:dependencies command.

I solved this problem. It just need add below code to root build.gradle

ext {
googlePlayServicesVersion = "11.0.0"
}

this work for me

  1. in root "build.gradle" add below code

ext {
googlePlayServicesVersion = "11.0.0"
}

  1. in "app/build.gradle"

dependencies {
...
implementation "com.google.android.gms:play-services-location:16.0.0" // <-- add this line
}

The solution for me was to remove googlePlayServicesVersion=12.0.1 in android/gradle.properties. It was lingering there from an older version of react-native-geolocation-service.

use resolution strategy

 def googlePlayServicesVersion = '11.0.+'

 allprojects {
     repositories {
         mavenLocal()
         jcenter()
         maven {
             url "$rootDir/../node_modules/react-native/android"
         }
         configurations.all {
             resolutionStrategy {
                 force "com.google.android.gms:play-services-ads:$googlePlayServicesVersion"
                 force "com.google.android.gms:play-services-location:$googlePlayServicesVersion" //add this!
             }
         }
     }
 }

This issue was very helpful. I ended up having to combine the solutions from two different comments above, in order to make it work. So, in case anybody (or future me) finds it useful:

Do both:

In top-level build.gradle, define googlePlayServicesVersion and add the resolution strategy:

def googlePlayServicesVersion = '16.0.0'

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        configurations.all {
            resolutionStrategy {
                force "com.google.android.gms:play-services-ads:$googlePlayServicesVersion"
                force "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
            }
        }
        google()
    }
}

And ALSO, in app/build.gradle, add this line to the dependencies:

implementation "com.google.android.gms:play-services-location:16.0.0"

Unfortunately it doesn't work for me

implementation "com.google.android.gms:play-services-location:16.0.0" // <-- add this line

Thanks it worked

inkwaris's solutions worked for me (fresh react native project: 0.59.3)

Same issue nothing worked (react-native 0.59.3)

You should always use a single version for all of your google play service modules (location, geocode, places etc.). Most of the libraries support project wide gradle configuration. So you should define the version you want to use in root build.gradle file. If a library does not support project wide gradle config, you have to override that libraries GPS dependency in your app/build.gradle file.

root build.gradle
ext {
    googlePlayServicesVersion = "12.0.0"
}
app/build.gradle (if you need to override manually)
compile(project(':react-native-package-name')) {
    exclude group: 'com.google.android.gms', module: 'module-name'
}
compile 'com.google.android.gms:module-name:12.0.0'

It's also documented in README.

Was this page helpful?
0 / 5 - 0 ratings