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

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

当我在 Android 移动版本 4.4 (lollipop) 上部署我的 Android 应用程序时,我收到一条消息“除非您更新 Google Play 服务,否则应用程序将无法运行”

我查看了我的安卓手机,可以看到 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'

最佳答案

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

如果您希望使用 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 服务时,这正是您看到的实际情况,这是应用程序开发人员可以做的最好的事情,因为您不能强制更新最终用户的设备和替代方案是让您的应用程序崩溃。

关于Android 应用向后兼容版本的 google play services API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39470967/

相关文章:

android - Google billing 消耗品和非消耗品

android - 如何在缩放或拖动(左,右,上,下)图像时准确定位另一个 View ?

android - appcompat版本出现错误

android - Android Studio 3.2.1 中的 Gradle 项目同步失败

gradle - 添加constraintLayout后无法同步项目

java - 在 Android 中处理 Google+ 登录

android - android中FutureTask和AsyncTask的区别

java - com.google.android :android:jar:4. 4.2_r3 在哪里?

java - 切换到 targetSdkVersion 28 (Android) 时出现 DefaultHttpClient NoClassDefFoundError

android - 为什么我在 Google Playstore 控制台中看到应用程序版本代码为 'Unknown'?