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

百般思念 提交于 2019-12-19 03:41:43

问题


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"


回答1:


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.




回答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

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

Now try to import.




回答3:


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.




回答4:


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 :)




回答5:


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.



来源:https://stackoverflow.com/questions/21079123/how-do-i-import-com-google-android-gms-in-android-studio-using-a-gradle-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!