Android 如何将 Google Play 服务修订版与安装版本相匹配?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24548032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:24:09  来源:igfitidea点击:

How do I match a Google Play Services revision with an install version?

androidgradlegoogle-play-servicesandroid-gradle-pluginbuild.gradle

提问by Mark Whitaker

Android SDK Manager notified me this morning that there was a new Google Play Services release to download: revision 18. So how do I find the corresponding long version number to put in my build.gradle file? All my test devices are running version 5.0.84, so I tried updating

Android SDK Manager 今天早上通知我有一个新的 Google Play Services 版本要下载:修订版 18。那么我如何找到相应的长版本号来放入我的 build.gradle 文件中呢?我所有的测试设备都运行 5.0.84 版,所以我尝试更新

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

to

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

But that resulted in an error:

但这导致了一个错误:

Gradle 'MyApp' project refresh failed: Could not find com.google.android.gms:play-services:5.0.84. Required by: {my app}Gradle settings

Gradle 'MyApp' 项目刷新失败:找不到 com.google.android.gms:play-services:5.0.84。需要:{我的应用}Gradle 设置

I'm running Android Studio 0.5.2 and building for API19 (I haven't upgraded to Android L/API20 yet): maybe that's the issue? But in general, how do you match a revision number shown in SDK Manager (e.g. 18) with a version code for build.gradle (e.g. 5.0.84)?

我正在运行 Android Studio 0.5.2 并为 API19 构建(我还没有升级到 Android L/API20):也许这就是问题所在?但一般来说,如何将 SDK Manager 中显示的修订号(例如 18)与 build.gradle 的版本代码(例如 5.0.84)匹配?

Here's my full build.gradle in case it helps:

这是我的完整 build.gradle 以防万一:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    // Avoid "Duplicate files copied in APK" errors when using Hymanson
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    // Was "compile 'com.android.support:support-v4:+'" but this caused build errors when L SDK released
    compile 'com.android.support:support-v4:19.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Support for Google Cloud Messaging
    // Was "compile 'com.android.support:appcompat-v7:+'" but this caused build errors when L SDK released
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:5.0.84'

    // Hymanson
    compile 'com.fasterxml.Hymanson.core:Hymanson-core:2.3.3'
    compile 'com.fasterxml.Hymanson.core:Hymanson-annotations:2.3.3'
    compile 'com.fasterxml.Hymanson.core:Hymanson-databind:2.3.3'
}

回答by Mark Whitaker

OK, I haven't quite managed to find a mapping of one to the other, but I've managed the next best thing which is to see a list of Play Services long version numbers installed on my development machine.

好吧,我还没有完全找到一个映射到另一个,但我已经完成了下一个最好的事情,那就是查看我的开发机器上安装的 Play 服务长版本号的列表。

For Windows, it's in [android-sdk]\extras\google\m2repository\com\google\android\gms\play-services(where [android-sdk]is the path to your Android SDK folder).

对于 Windows,它位于[android-sdk]\extras\google\m2repository\com\google\android\gms\play-services[android-sdk]Android SDK 文件夹的路径在哪里)。

On a Mac, it's inside the Android.app package: browse to sdk/extras/google/m2repository/com/google/android/gms/play-services

在 Mac 上,它位于 Android.app 包内:浏览到 sdk/extras/google/m2repository/com/google/android/gms/play-services

The latest version on my machine was 5.0.77 (not 5.0.84), and putting that in my build.gradle worked fine.

我机器上的最新版本是 5.0.77(不是 5.0.84),把它放在我的 build.gradle 中工作正常。

Here's the kind of thing you should see at that location:

以下是您应该在该位置看到的内容:

Google Play Services versions on Windows

Google Play Services versions on Windows

Google Play Services versions on OSX

Google Play Services versions on OSX

回答by Jamie Nhu

What I did in my project was download google play service and open the project structure > dependencies tab and click on the plus button and choose google play service. I dont have to care about the version anymore

我在我的项目中所做的是下载 google play 服务并打开项目结构 > 依赖项选项卡,然后单击加号按钮并选择 google play 服务。我再也不用关心版本了