5

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"

MikeWallaceDev
  • 1,458
  • 2
  • 14
  • 28

5 Answers5

13

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.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
2

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.

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • I put the dependency on the first line as you said. That doesn't seem to help. When I go into the project structure the dependencies (all 3) are actually all there. This is just getting weirder... – MikeWallaceDev Jan 12 '14 at 21:10
  • have you looked on images too. You need to add dependency from Project structure too . This seems a bug in Android studio I filed it already . Have a look https://plus.google.com/104155298861246802294/posts/DPB6AZT7zZj – Piyush Agarwal Jan 12 '14 at 21:21
  • Have you synced your project with gradle too ? – Piyush Agarwal Jan 13 '14 at 10:25
  • Yes, I have. But more importantly I discovered that this also happens on the command line, so it has nothing to do with Android Studio. I'm really at a loss here... – MikeWallaceDev Jan 13 '14 at 16:32
0

I think the most important question is what you want to achieve. Not all code is under this package. Not even sure which one is.

Stefan Hoth
  • 2,675
  • 3
  • 22
  • 33
0

As noted before, this is a bug with Android Studio. It just don't recognize the path for classes and shows you like if there is an error. If you try compiling you'll see that everything just work fine.

A googler recently said it'll be addressed in this week release, so, be patient and lets see whats coming.

The fact that AS is in Preview mode tell us this sort of things are going to happen :)

Erik Mejia
  • 104
  • 1
  • 6
0

Android studio is crazy one, I think. It's removed "Import module" function and you can do "New module" only. If you are developed on Eclipse, you need export all your projects to Gradle before switch to Androids studio (WTF?)

I prefer "IntelliJ IDEA Community Edition", although It's similar Android studio but it's better than Android studio (at least until now). You just import your project as eclipse format, IntelliJ IDEA will detect dependences libraries automatic (May be you need import jar libraries by hand) and rebuild project. That Done.

Tran Hieu
  • 5,325
  • 1
  • 13
  • 10