首页 > 解决方案 > 如何根据构建风格禁用 Google 的应用内更新?

问题描述

我正在尝试实现谷歌的应用内更新。当试图直接从 AndroidStudio 运行应用程序时,我得到了这个异常:

com.google.android.play.core.install.InstallException: Install Error(-10): The app is not owned by any user on this device. An app is "owned" if it has been acquired from Play. (https://developer.android.com/reference/com/google/android/play/core/install/model/InstallErrorCode#ERROR_APP_NOT_OWNED)

我了解当应用程序未从 Play 商店安装时,谷歌无法检查更新。我的目标是在应用程序处于未从 Play 商店安装的测试版本中时禁用此功能,因为在这些情况下,我无论如何都不关心应用程序更新。
如何根据构建风格禁用此检查?

我已经阅读了本指南,但它没有提到任何我想要的东西。

标签: androidgoogle-playin-app-updategoogle-play-core

解决方案


只需app/build.gradle为每种构建类型定义一些属性

buildTypes {
    debug {
        buildConfigField 'boolean', 'UPDATE_ENABLED', 'false'
    }
    release {
        buildConfigField 'boolean', 'UPDATE_ENABLED', 'true'
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

同步后,您可以请求if(BuildConfig.UPDATE_ENABLED)并检查更新


推荐阅读