简体   繁体   English

Android Studio构建Gradle同步失败

[英]Android studio build gradle sync failed

I am trying to add google play service to my project but it gives me error when I try to edit build (Gradle). 我正在尝试将Google Play服务添加到我的项目中,但是当我尝试编辑版本(Gradle)时却给我错误。

在此处输入图片说明

How can I fix it? 我该如何解决?

In your configuration there some issues. 在您的配置中存在一些问题。

  • You are using the wrong build.gradle file. 您使用了错误的 build.gradle文件。
    It is your top-level file. 它是您的顶级文件。 You should add this line in your app/build.gradle 您应该在app/build.gradle添加此行

  • There is a typo. 有一个错字。 You are missing the ' at the end of the line compile. 您在编译行的末尾缺少'

  • Use an updated version . 使用更新的版本

For example use: 例如使用:

apply plugin: 'com.android.application'
        ...

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

Finally refer this official doc for more info. 最后,请参考此官方文档以获取更多信息。

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. 在6.5之前的Google Play服务版本中,您必须将整个API包编译到您的应用中。 In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit. 在某些情况下,这样做会使将应用程序中的方法数量(包括框架API,库方法和您自己的代码)保持在65,536个限制以下变得更加困难。

For example if you need to make only your app aware of location updates add compile 'com.google.android.gms:play-services-location:8.1.0' only in gradle or if you need only map choose compile 'com.google.android.gms:play-services-maps:8.1.0'. 例如,如果仅需要让您的应用知道位置更新,则仅在gradle中添加编译'com.google.android.gms:play-services-location:8.1.0';如果仅需要地图,则选择编译'com.google .android.gms:play-services-maps:8.1.0'。

Please replace 请更换

compile 'com.google.android.gms:play-services:3.1.36

with

compile 'com.google.android.gms:play-services:3.1.36'

您可以尝试做的一件事是,右键单击“依赖项”选项卡上的应用程序打开模块设置 ,然后单击“ +”图标并在其中添加“ com.google.android.gms:play-services:8.1.0” ,然后单击搜索图标并添加该依赖项,

So i don't want to elaborate what you had done wrong as my colleagues figured it out.I like to say, while playing with Google Play Service 所以我不想说出我的同事弄清楚你做错了什么。我想说的是,在使用Google Play服务时

Selectively compile APIs into your executable 选择性地将API编译为可执行文件

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. 在6.5之前的Google Play服务版本中,您必须将整个API包编译到您的应用中。 In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit. 在某些情况下,这样做会使将应用程序中的方法数量(包括框架API,库方法和您自己的代码)保持在65,536个限制以下变得更加困难。

For example if you need to make only your app aware of location updates add compile 'com.google.android.gms:play-services-location:8.1.0 ' only in gradle or if you need only map choose compile 'com.google.android.gms:play-services-maps:8.1.0' . 例如,如果只需要让您的应用知道位置更新,则仅在gradle中添加编译'com.google.android.gms:play-services-location: 8.1.0 ' ;或者如果您仅需要地图,则选择编译'com.google .android.gms:play-services-maps:8.1.0'

Thank you. 谢谢。

Visit for more. 访问更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM