Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import com.google.android.gms.* in Android Studio using a Gradle build?

I have followed the procedure as described here : Setup I have clicked on the little 'Sync project with Gradle' button. Gradle and Android Studio seem to find everything but then I can't actually use the gms code. If I try to import, I will get autocomplete for com.google.android.gms but no further. I have updated all the packages with Android SDK Manager.

  • I'm running Android Studio 0.4.2.
  • My minSdk is set to 9
  • my build.gradle includes compile 'com.google.android.gms:play-services:4.0.30'

As far as the procedure is concerned I should be ready to code, but it just doesn't work. Any ideas?

[Edit, added info]

I can find the ComGoogleAndroiddGmsPlayServices3265.aar file in my exploded bundles directory. Inside of that file I also find the common directory and inside that I find the GooglePlayServicesUtil.class (which is what's not being found in my app)

I am lost.

[Edit 2]

The problem is not specific to Google Play Services OR Android Studio. I tried adding another library (HoloColorPicker) and had the same results. However, I was able to add the library's resources to my project! I was able to add them in my XML layouts and view them in my application. I was able to interact with them, they worked fine. The problem arose again when I tried to reference them in the code. Exactly like the case with gms, I had code completion when trying to import up to the point of the actual class, and I could not declare the class in the code.

I was able to use the library by cloning it and importing the project.

Also, this is not an Android Studio problem because the same thing happens on the command line with "./gradlew clean build"

like image 997
MikeWallaceDev Avatar asked Jan 12 '14 19:01

MikeWallaceDev


2 Answers

This is a current bug in Android Studio: https://code.google.com/p/android/issues/detail?id=64508 to be fixed this week.

The workaround is to close the project, delete the .iml files and .idea project and re-import the project.

like image 184
ianhanniballake Avatar answered Nov 02 '22 23:11

ianhanniballake


Keep Your compile 'com.google.android.gms:play-services:4.0.30' as very first line in build.gradle dependencies like

    dependencies {
       compile 'com.google.android.gms:play-services:4.0.30'
       compile 'com.android.support:support-v4:18.0.+'
       compile 'com.android.support:appcompat-v7:+'

   }

`

Open File> Project Structure and do the following steps

enter image description here

Select your main module in which you want to add dependency and click on OK.

enter image description here

Now try to import.

like image 27
Piyush Agarwal Avatar answered Nov 02 '22 22:11

Piyush Agarwal