使用 Gradle 将 Google Play 服务添加到 Android Studio [英] Add Google Play Services to Android Studio using Gradle
问题描述
我正在开发简单的地图应用程序,我添加了 google-play-services.jar 及其对 gradle 的引用
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$styleable atcom.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)
我尝试了几种方法,同样的问题,我只想将谷歌服务添加到带有 Gradle 0.6+ 的 Android Studio 0.3
I tried several ways, same issue, I just want to add google services to Android Studio 0.3 with Gradle 0.6+
推荐答案
正如@Matt 所说,这是正确的,我在这里也涵盖了我在答案中没有找到的内容.
As @Matt said, it is correct, I am here covered also which I did not find in the answer.
要在您的应用程序项目中添加 Google 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) 在您的依赖项中添加新的,在这里您可以在每次更新 Google Play 服务时更新版本号.
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) 现在最后重要的是保存你的文件并点击 Sync with Gradle
Files 在工具栏中.
3) Now Lastly important save your file and click on Sync with Gradle
Files in the toolbar.
这篇关于使用 Gradle 将 Google Play 服务添加到 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!