编译谷歌播放服务

时间:2017-04-28 10:08:15

标签: android gps dependencies google-play-services

我知道这个问题对于尝试使用android的人来说非常简单,但请帮助我。 我按照本教程: https://examples.javacodegeeks.com/android/android-location-api-using-google-play-services-example/ 到我的设备的纬度和经度。

我的问题是这部分:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile "com.google.android.gms:play-services:8.3.0"
}

我尝试用我自己的代码做同样的事情:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-service:8.3.0'
testCompile 'junit:junit:4.12'
}

但是当我同步项目时,我收到了这个错误:

fail to resolve:com.google.android.gms:play-service:8.3.0

所以在我的SDK管理器中我下载了谷歌播放服务,但这是我的问题: 如何查看“com.google.android.gms:play-service”的版本 ???

编辑:

我搜索的版本是10.2.1 如果您遇到同样的问题,请检查文件 - >项目结构 - >依赖关系 - >'+'并检查版本。它现在适用于AVD,但有了它,你会遇到一个新的错误:

我的gradle.build(app)

manifest

有错误: enter image description here

编辑2:如果您有相同的错误,请检查https://developers.google.com/android/guides/setup 并选择你想要的东西(例如编译'com.google.android.gms:play-services-location:10.2.1')

1 个答案:

答案 0 :(得分:1)

确保在同步gradle时连接到互联网。它只是第一次下载gradle。

确保在SDK Manager中安装/更新最新的Google信息库和Google Play服务

enter image description here



避免使用compile 'com.google.android.gms:play-services:10.2.1'因为非常重并导致Dex问题。改为使用个体依赖。如果您坚持要使用它,请启用multiDexEnabled true

enter image description here


如果您使用的是Google Firebase,请不要忘记添加classpath 'com.google.gms:google-services:3.0.0',然后在apply plugin: 'com.google.gms.google-services'

的底部添加此app/build.gradle

P / S: 请使/ cache失效并重新启动AS