简体   繁体   中英

Unable to get provider com.google.android.gms.measurement.AppMeasurementContentProvider

I tried to Set up GCM in my project as given in Set up a GCM Client App on Android and to Set Up Google Play Services added dependency

  compile "com.google.android.gms:play-services-gcm:8.4.0"

to the dependency section of my application's build.gradle file.

And In the root gradle file add classpath as given in sample project(Sample cloned from $ git clone https://github.com/googlesamples/google-services.git ) as

dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0-beta6'
    classpath 'com.google.gms:google-services:2.0.0-beta6'
}

It's building fine, but it crashes on launch with the following stack trace :

java.lang.RuntimeException: Unable to get provider com.google.android.gms.measurement.AppMeasurementContentProvider: java.lang.NullPointerException: null reference at android.app.ActivityThread.installProvider(ActivityThread.java:5156) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: null reference at com.google.android.gms.common.internal.zzx.zzy(Unknown Sou rce) at com.google.android.gms.measurement.internal.zzt.zzaU(Unknown Source) at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source) at android.content.ContentProvider.attachInfo(ContentProvider.java:1748) at android.content.ContentProvider.attachInfo(ContentProvider.java:1723) at android.app.ActivityThread.installProvider(ActivityThread.java:5153) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.interna l.os.ZygoteInit.main(ZygoteInit.java:616)

Also tried related stack questions:

  1. Updating Play services from 8.1 to 8.3 with Proguard enabled
  2. Error on some devices - couldn't find class 'com.google.android.gms.measurement.internal.zzz'

As answered in 1st link tried classpath

classpath 'com.google.gms:google-services:1.5.0'

and as answered in 2nd link,tried Multidex also with no success.

Also tried for Application Measurement adding

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <integer name="google_app_measurement_enable">0</integer>
</resources>

as suggested in Play Services Release notes .

Note : sample code running.


Update :

Interesting thing is that same error even if I add only dependency

  compile "com.google.android.gms:play-services-gcm:8.4.0"

in my app gradle file(Note : Only one line added in Existing project).And there is no error after adding

compile "com.google.android.gms:play-services-gcm:8.1.0"

ie the token works on 8.1.0 .Interesting,isn't?

Did you remember to add the plugin to the end of your app-level build.gradle file? ...

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

You specifically need to add it to the very end of the file.

Take a look here for reference: https://github.com/googlesamples/google-services/blob/master/android/gcm/app/build.gradle

There is also a bug report opened on this issue: Issue 193112

From Android studio menu go to:

  • Build → Clean Project

  • Build → Rebuild Project

  • Run the app. No more crash.

Note: I am using the latest version of play-services:

compile 'com.google.android.gms:play-services:8.4.0'

Try to change your classpath dependency, instead of ' classpath 'com.google.gms:google-services:2.0.0-beta6 '', use classpath ' classpath 'com.google.gms:google-services:1.5.0' '.

Here is a related stack overflow ticket , you may check the solution offered by community:. It was stated that they already filed bug ticket and the said fix has been implemented in release 1.5.0 of the foot service plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM