Import Google Play Services library into Android Studio

I have an Android project that was developed entirely in Android Studio (currently version 4.2, gradle version 1.9-all). I want to add functionality from Google Play services.

The project cannot resolve GooglePlayServicesUtil , and when I enter the import manually (shown below), I get Cannot resolve symbol 'common' .

 import com.google.android.gms.common.GooglePlayServicesUtil; 

Any idea what I need to do to enable GooglePlayServicesUtil ?

What i tried

From Configuring Google Play Services , it looks like I just need to add the com.google.android.gms:play-services:4.+ dependency com.google.android.gms:play-services:4.+ to my build.gradle file (and the resync project files using gradle) to make the SDK available to my project. I get an β€œexploded kit” in ProjectName/module/build/exploded-bundles , but that doesn't seem like a trick.

I already have Google Play services, Android support repository and Google Repository installed from SDK manager. I also uninstalled and reinstalled them several times :)

Edit:

Maybe I need to manually add google_play_services as a Project / Global Library? I tried without success.

I am trying to verify that I am developing a platform API using Google Services (if possible), but I'm not sure if this is the case. Nothing of me changes anything.

The external libraries of my project show:

  • <Android API 19 Platform>
  • <1.7>
  • Joda-Time 2.3
  • Support-v4-13.0.0

Source

This is my ProjectName / module / build.gradle file:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.7.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '19.0.1' defaultConfig { minSdkVersion 17 targetSdkVersion 19 versionCode 1 versionName "1.0" } buildTypes { release { runProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } signingConfigs { } productFlavors { } } dependencies { compile 'com.google.android.gms:play-services:4.+' compile 'joda-time:joda-time:2.3@jar' } 

The number of com.google.android.gms.version in my manifest stops. Here is my ProjectName / module / src / main / AndroidManifest.xml file:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android" > <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.android.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity"/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <provider android:name=".DataProvider" android:authorities="com.example.android.provider" > </provider> <receiver android:name=".WidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /> </receiver> <service android:name=".DatabaseService" /> <service android:name=".WidgetProvider$UpdateService" /> </application> </manifest> 

Here is my MainActivity where I am trying to check if GooglePlayServices is available:

 package com.example.android; import android.app.Activity; import android.os.Bundle; import android.util.Log; import com.google.android.gms.common.GooglePlayServicesUtil; public class MainActivity extends Activity { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onResume() { Log.i(TAG, "onResume"); GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); } } 
+45
java android android-studio google-play-services gradle
Jan 12 '14 at 23:19
source share
7 answers

Try this one time and make sure that you are not getting any errors in the project structure, stating that "ComGoogleAndroidGmsPlay is not added"

Go to File > Project Structure and check all below. If an error is displayed, click the marked red lamp and click Add To Addiction.

Gms dependency

This is a bug in Android Studio and fixed for the next version (0.4.3)

+32
Jan 13 '14 at 8:39
source share

I had a similar problem. Cannot resolve com.google.android.gms.common.

I followed the http://developer.android.com/google/play-services/setup.html setup guide and it works!

Summary:

  • Installed / Updated Google Play Services and Google Repository from SDK Manager
  • Added dependency in build.gradle: compile 'com.google.android.gms:play-services:4.0.30'
  • Updated AndroidManifest.xml with <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
+20
Jan 27 '14 at 22:03
source share

I solved the problem by installing the Google Play service package in sdk manager.

After that, create a new application, and in build.gradle add this

 compile 'com.google.android.gms:play-services:4.3.+' 

Like this

 dependencies { compile 'com.android.support:appcompat-v7:+' compile 'com.google.android.gms:play-services:4.3.+' } 
+7
Jul 02 '14 at 4:37
source share

After several hours of working with the same problem, note that if your jar is in the libs folder, it will cause a problem if you set it to "Dependencies", so I just comment on the file dependencies and save a single value with

addictions

 //compile fileTree(dir: 'libs', include: ['*.jar']) <-------- commented one compile 'com.google.android.gms:play-services:8.1.0' compile 'com.android.support:appcompat-v7:22.2.1' 

and the problem was resolved.

+4
Sep 25 '15 at 22:04
source share

I just tried your build.gradle and it worked great for importing GMS, so this is not a problem.

This was with Google Play services (rev 13) and Google Repository (rev 4) . Check if they are installed again :)

+3
Jan 13 '14 at 0:26
source share

I have the same problem. I was just trying to rebuild, clean, and restart, but no luck. Then i just delete

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

from build.gradle and resync. After that I laid it down again and repeated. Next to this, I clean the project and the problem is gone!

I hope this helps any of you facing the same.

+1
Aug 02 '16 at 6:46
source share

//gradle.properties

systemProp.http.proxyHost = www.somehost.org

systemProp.http.proxyPort = 8080

systemProp.http.proxyUser = identifier

systemProp.http.proxyPassword = password

systemProp.http.nonProxyHosts = * nonproxyrepos.com |. Local

-2
Apr 23 '15 at 7:11
source share



All Articles