Android的工作室与谷歌播放服务 [英] Android Studio with Google Play Services

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

问题描述

我想测试谷歌播放服务与全新的Andr​​oid工作室。 我有一个依赖于google_play_services.jar项目。 但是,当我试图重建项目中,我得到了以下错误:

I'm trying to test Google Play Services with the new Android Studio. I have a project with a dependency to the google_play_services.jar. But when I try to Rebuild the project I get the following errors:

Information:[TstGP3-TstGP3] Crunching PNG Files in source dir: C:\Users\ans\AndroidStudioProjects\TstGP3\TstGP3\src\main\res
Information:[TstGP3-TstGP3] To destination dir: C:\Users\ans\AndroidStudioProjects\TstGP3\build\classes\res-cache\TstGP3-TstGP3
Information:Compilation completed with 2 errors and 0 warnings in 2 sec
Information:2 errors
Information:0 warnings
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\Android_BuildConfig_Generator\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\BuildConfig.java
    Error:Error:line (4)error: duplicate class: com.example.tstgp3.BuildConfig
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\aapt\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\R.java
    Error:Error:line (10)error: duplicate class: com.example.tstgp3.R

似乎它有两个BuildConfig文件,也两个R类。我怎样才能解决这个问题?

It seems that it has two BuildConfig files and also two R classes. How can I resolve the issue?

编辑:

我已经注意到,编译器编译2 R.java文件:一个是在我的项目文件夹中,另外一个是位于文件夹%USERPROFILE%.AndroidStudio preVIEW 所以,我试图排除在编译器设置这个preVIEW文件夹,现在它的工作。 这个问题只有我开始后继续使用谷歌播放服务类在我的项目出现。 我将AP preciate如果有人可以解释这背后的问题的原因。

I have noticed that the compiler compiles two R.java files: the one that is in my project folder and another one that is located in the folder %USERPROFILE%.AndroidStudioPreview So, I tried to exclude this "Preview" folder in the compiler settings and now it's working. This issue only occurs after I have started to use Google Play Services classes in my project. I will appreciate if someone can explain the reason behind this problem.

推荐答案

所有这些答案都是错的,因为摇篮插件v0.4.2发布的Andr​​oid下的谷歌工作室的建立发挥服务是直线前进。你并不需要输入任何JAR或添加任何项目库,也没有在Android的工作室添加任何新的模块。什么,你需要做的就是添加正确的依赖关系到build.gradle文件。请看看这些链接:摇篮插件v0.4.2更新,的New构建系统和<一href="http://docs.google.com/viewer?a=v&pid=sites&srcid=YW5kcm9pZC5jb218dG9vbHN8Z3g6MTMzZWIxYTIxMDZhYmE5Nw">this样品

All those answers are wrong, since the release of gradle plugin v0.4.2 the setup of google play services under android studio is straight forward. You don't need to import any jar or add any project library nor add any new module under android studio. What you have to do is to add the correct dependencies into the build.gradle file. Please take a look to those links: Gradle plugin v0.4.2 update, New Build System, and this sample

正确办法这样做如下:

首先你必须为启动SDK管理器,然后下载并安装设下的群众演员以下文件: Android的支持库谷歌播放服务谷歌库的。

First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.

重新启动机器人工作室,并打开构建摇篮文件。您必须修改build.gradle文件看起来像这样根据依赖关系:

Restart android studio and open the build gradle file. You must modify your build.gradle file to look like this under dependencies:

dependencies {
    compile 'com.google.android.gms:play-services:6.5.87' 
 }

最后syncronise项目(按钮的AVD管理器的左侧)。

And finally syncronise your project (the button to the left of the AVD manager).

由于6.5版本,你可以包含完整库(非常大),或仅仅是模块,你需要(最佳选择)。也就是说,如果你只需要谷歌地图和分析可以更换previous例如用下列操作之一:

Since version 6.5 you can include the complete library (very large) or just the modules that you need (Best Option). I.e if you only need Google Maps and Analytics you can replace the previous example with the following one:

dependencies {  
    compile 'com.google.android.gms:play-services-base:6.5.87'    
    compile 'com.google.android.gms:play-services-maps:6.5.87'  
}

您可以在这里找到完整的依赖关系列表

You can find the complete dependency list here

一些旁注:

  • Use the latest play services library version. If it's an old version, android studio will highlight it. As of today (February 5th is 6.5.87) but you can check the latest version at Gradle Please
  • After a major update of Android Studio, clean an rebuild your project by following the next instructions as suggested in the comments by @user123321

cd到项目文件夹
./gradlew干净
./gradlew建

cd to your project folder
./gradlew clean
./gradlew build

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

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