【问题标题】:Multiple errors during the gradle sync when I try to add Google Service library to the dependencies当我尝试将 Google 服务库添加到依赖项时,gradle 同步期间出现多个错误
【发布时间】:2017-10-03 20:03:37
【问题描述】:

我想使用 AdMob 向我的应用添加一些广告,该网站说我需要将 Google 服务添加到依赖项中才能使用此功能。因此,使用 Android Studio,我转到 File->Project Structure->app->Dependencies,单击“+”按钮并搜索“play-services”。我发现的是“com.google.android.gms:play-services:9.4.0”所以我将它添加到依赖项中。然而,在 gradle 同步期间,Android Studio 会发送一些错误并停止 gradle 同步。

这是我从同步中获得的日志:http://pastebin.com/ZpN4RUcm

这里有一些可能有用的数据:

  • 编译 SDK 版本:API 17
  • 构建工具版本:23.0.1
  • 安卓 工作室 2.1.2

这是我的主要 gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    dependencies {
            classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

这是我的应用程序 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:17'
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "com.serpenssolida.glowdodger"
        minSdkVersion 10
        targetSdkVersion 17
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
       }
   }

   repositories {
       mavenCentral()
   }

   dependencies {
       compile 'com.android.support:support-v4:17.0.0'
       compile files('libs/processing-core.jar')
       compile project(':facebook')
       compile 'com.google.android.gms:play-services:9.4.0'
   }

我怎样才能摆脱所有的错误?

【问题讨论】:

    标签: android android-gradle-plugin google-play-services


    【解决方案1】:

    如下更改您的应用 gradle 文件,然后重试:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion '24'
        buildToolsVersion '24.0.2'
        ...
    }
    

    【讨论】:

    • 我试过了,没用。输出保持不变。编辑:实际上 gradle 给了我一个警告。已修复,我再试一次。
    • 经过一些麻烦后,我设法让我的应用程序正常运行!按照您的回答编辑gradle已经奏效了! +1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2020-07-29
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多