2

Recent updation to com.google.android.gms:play-services-ads:8.4.0 results in this error. This does not happen when com.google.android.gms:play-services:8.4.0 is used, but it bloats the apk size significantly. Also to implement in-app billing, it is needed to check whether Google Play services are installed or not before starting a purchase.

Is there a workaround for this?

Piyush
  • 1,744
  • 1
  • 15
  • 28
  • This class is included in `com.google.android.gms:play-services-base:8.4.0` and `play-services-ads` does not depend on it. Meaning you don't need it. Seems like ads don't need Google Play services installed. – Eugen Pechanec Feb 14 '16 at 20:37
  • But how do I check if play services are installed then? – Piyush Feb 14 '16 at 20:41
  • You [don't have to](http://stackoverflow.com/a/27195547/1676363) - it works whether it is there or not. – ianhanniballake Feb 14 '16 at 20:44
  • I know that ads work on devices without Play services, but since each result in onActivityResult is passed to iabHelper.handleActivityResult(), this would cause a NullPointerException. Isn't there a workaround for this rather than using try catch? – Piyush Feb 14 '16 at 20:50
  • What are you talking about? How is this related to the question? Where's the code? What's a iabHelper? – Eugen Pechanec Feb 14 '16 at 23:25
  • IabHelper is a helper class for implementing in-app billing. I forgot to mention this in the question. – Piyush Feb 15 '16 at 11:04
  • Possible duplicate of [Import Google Play Services library in Android Studio](http://stackoverflow.com/questions/21081598/import-google-play-services-library-in-android-studio) – pRaNaY Feb 15 '16 at 11:09
  • I faced same problem, but solved using this: http://stackoverflow.com/a/42063112/4531507 – Rahul Sharma Feb 06 '17 at 08:43

2 Answers2

4

All you need to do in order to use GooglePlayServicesUtil is include the following dependency in your build.gradle:

compile 'com.google.android.gms:play-services-base:10.2.0'

Here you can see all the individual Play Services dependencies that you can pick from: https://developers.google.com/android/guides/setup#split

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
0

I faced same problem but in my case i didn't added any other dependency even my problem solved by just changing the position of apply plugin: 'com.google.gms.google-services' in the build.gradle(Modile: app) file.

Line

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

was written at the last in the gradle file. Remove this from here and add it to the top, below the line apply plugin: 'com.android.application' Like this:

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

and sync now. Problem solved.

Rahul Sharma
  • 5,949
  • 5
  • 36
  • 46