我正在使用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 Library
,Google Support Repository
,Google Play Services
。
这是我的libs目录
我的SDK版本如:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="20" />
我做错了什么?如果有人有任何想法,请告诉我。
答案 0 :(得分:5)
如果您通过以下方式提供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'])
确保从那里取出罐子。 就此而言,您不应该通过特定的罐子包含其他库。
而不是:
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。)