Android应用向后兼容版本的google play服务API

时间:2016-09-13 13:09:54

标签: android android-gradle google-play-services google-maps-android-api-2 mobile-application

当我在Android移动版4.4(棒棒糖)上部署我的Android应用程序时,我收到的消息是"应用程序不会运行,除非您更新Google Play服务"

我查看了我的Android手机,可以看到Google Play服务版本是5.1.89。我知道在我的代码中我使用的是8.4.0

我不希望Android向用户显示弹出窗口来更新Google Play服务

任何Android移动应用专家都可以帮我解决这个问题。 如何在不要求用户更新Google服务的情况下使我的应用向后兼容?

我的build.gradle如下

  apply plugin: 'com.android.application'

  android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

buildTypes {
    debug {
        debuggable true
    }
}
        defaultConfig {
    applicationId "com.me"
    minSdkVersion 17
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dexOptions {
    preDexLibraries = false
}
packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
lintOptions {
    checkReleaseBuilds false
}

  }

 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'

}

1 个答案:

答案 0 :(得分:4)

Google Play Services overview所述,该服务由两部分组成:在构建时链接到应用程序的客户端库,以及客户端库使用inter连接到的Google Play服务APK进程通信(IPC)。

如果您希望使用Google Play服务的新功能,或者如果您遇到以后版本中修复的错误,通常只需要升级客户端库。

Google Play服务APK作为后台服务运行,为您的应用程序提供实际的Google服务。借助这种拆分模式,Google可以及时向最终用户设备推出新功能,服务更新和关键错误修复,而无需等待运营商或设备制造商实施这些修复程序。

因此,Google Play服务APK必须向后兼容以前发布的客户端版本,以避免每次更新时破坏开发人员的应用程序。

然而,相反的情况并非如此。如果您使用特定版本的客户端库构建应用程序,则安装的Google Play服务APK版本不得早于此版本。

因此,如果您针对库版本5.1.89构建,您的应用程序将与APK的8.4.0版本一起使用,但如果安装的版本是5.0.0,则不会。

行为良好的应用程序在访问服务之前始终会检查已安装的Google Play服务APK的可用性和版本,如Google Play服务setup guide中所述。这正是您在提示最终用户更新设备上的Google Play服务时所看到的操作,并且它是应用程序开发人员可以做的最好的,因为您无法强制更新最终用户的设备和替代方案是让您的应用程序崩溃。