【问题标题】:Android Studio with Gradle incompatibility (Google Play Services issue)与 Gradle 不兼容的 Android Studio(Google Play 服务问题)
【发布时间】:2014-09-16 16:51:52
【问题描述】:

我正在使用 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;

我检查了很多网站(包括 Stackoverflow.com)。它们都不适合我。

我有最新版本的Google Support LibraryGoogle Support RepositoryGoogle Play Services

这是我的 libs 目录

我的 SDK 版本如:

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

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

【问题讨论】:

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


    【解决方案1】:

    如果您通过以下方式包含 Play 服务:

    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)。

    【讨论】:

    • 它不起作用。我之前也尝试过。我得到同样的错误。
    • 还是不行。但错误更改为“多个 dex 文件定义 Landroid/support/v4/AccessibilityService/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;”
    • 在您的 libs 文件夹中看到 v4-support 库了吗?删除它,就像我说的那样。
    • 我知道了。您的意思是物理删除 jar 文件。现在可以了,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    相关资源
    最近更新 更多