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

18,071

Solution 1

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

Solution 2

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'

Solution 3

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.

Share:
18,071
Giru Bhai
Author by

Giru Bhai

Someone who works @ CT

Updated on June 05, 2022

Comments

  • Giru Bhai
    Giru Bhai almost 2 years

    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 Source) 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.internal.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"
    

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

  • Giru Bhai
    Giru Bhai about 8 years
    Thanks to answer but Its not working even did restart AS.And also as suggested by play services "From version 6.5, you can instead selectively compile Google Play service APIs into your app".So we add ` compile "com.google.android.gms:play-services-gcm:8.4.0" compile "com.google.android.gms:play-services-gcm:8.4.0" to escape from dex limit.
  • SBerg413
    SBerg413 about 8 years
    @GiruBhai - I actually did read the question "properly", my friend. You had failed to mention that you included the plugin line in your Gradle file. I also mentioned a bug report on this issue, which there are several. I would suggest that you read through those bug reports a bit more. Good luck!