添加使用摇篮谷歌播放服务到Android工作室 [英] Add Google Play Services to Android Studio using Gradle

查看:108
本文介绍了添加使用摇篮谷歌播放服务到Android工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进出口工作简单的地图应用程序,我加了谷歌播放的,services.jar及其参考摇篮

Im working on simple map app, I added google-play-services.jar and its reference to gradle

dependencies {
    compile files('libs/android-support-v4.jar', 'libs/google-play-services.jar')
}

主要活动:

setContentView(R.layout.activity_mapui);

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

布局文件

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"/>

但在设备上的应用程序崩溃

But the app crashes on the device

E / AndroidRuntime:致命异常:主要   java.lang.NoClassDefFoundError的:com.google.android.gms.R $设置样式为   com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(未知   源)以com.google.android.gms.maps.MapFragment.onInflate(未知   来源)

E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source) at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)

我试了几种方法,同样的问题,我只是想谷歌的服务添加到Android 0.3工作室与摇篮0.6 +

I tried several ways, same issue, I just want to add google services to Android Studio 0.3 with Gradle 0.6+

推荐答案

正如@马特说,这是正确的,我在这里也包括我没有找到答案。

As @Matt said, it is correct, I am here covered also which I did not find in the answer.

要加入谷歌Play业务库的应用程序项目,请按照下列步骤操作: -

To add the Google Play Service library in your application project, follow below steps :-

1)打开应用程序的模块目录的 build.gradle 文件。见截图

1) Open the build.gradle file of your application module directory. See screenshot

2)新增在你的依赖条件,在这里您更新无论您何时更新谷歌播放服务的版本号。

2) Add new in your dependecies, here you to update the version number whenever you update the Google Play Service.

dependencies {
    ...
    compile 'com.google.android.gms:play-services:4.2.42'
    compile files('src/main/libs/gson-2.2.4.jar')

}

3)现在,最后重要的保存文件,然后点击同步与摇篮文件在工具栏中。

3) Now Lastly important save your file and click on Sync with Gradle Files in the toolbar.

这篇关于添加使用摇篮谷歌播放服务到Android工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆