代码之家  ›  专栏  ›  技术社区  ›  JustWork

Android Studio与Gradle不兼容(Google Play Services问题)

  •  0
  • JustWork  · 技术社区  · 11 年前

    我正在用android Studio 0.8.9开发android应用程序。我正在使用Gradle构建我的项目。

    我想包括 google-play-services.jar 文件,以便使用推送通知api。

    我已将这些语句添加到gradle(应用程序层)文件中,如下所示:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile files('libs/google-play-services.jar')
        compile files('libs/android-support-v4.jar')
        compile files('libs/gson-2.2.3.jar')
        compile files('libs/volley_23042014.jar')
        compile 'com.google.android.gms:play-services:5.2.08'
    }
    

    但它从未奏效。我收到以下错误:

    Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
    

    我查了很多网站(包括Stacksoverflow.com),但没有一个对我有用。

    我有最新版本的 Google Support Library , Google Support Repository , Google Play Services .

    这是我的libs目录

    lbs directory

    我的SDK版本如下:

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="20" />
    

    我做错了什么?如果有人有任何想法,请告诉我。

    1 回复  |  直到 11 年前
        1
  •  5
  •   Scott Barta    11 年前

    如果您通过以下方式提供游戏服务:

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

    你不需要这个:

    compile files('libs/google-play-services.jar')
    

    所以只需移除它。

    由于依赖项的第一行将使它自动拾取您放入libs目录中的任何jar文件:

    compile fileTree(dir: 'libs', include: ['*.jar'])
    

    确保你也从那里取下罐子。 因此,有些其他库不应该通过特定的jar包含。

    而不是:

    compile files('libs/android-support-v4.jar')
    compile files('libs/gson-2.2.3.jar')
    

    使用此选项:

    compile 'com.android.support:support-v4:20.0.0'
    compile 'com.google.code.gson:gson:2.2.3
    

    (请注意,GSON的更新版本可用)。