How can I disable Google's in-app update based on build flavor?

5.2k views Asked by At

I am trying to implement google's in-app updates. When trying to run the app directly from AndroidStudio I got this exception:

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)

I understand that google can't check for updates when the app wasn't installed from the play store. My goal is to disable this feature while the app is in a testing build that isn't installed from the play store because in these situations I don't care about app updates anyway.
How can I disable this check depending on the build flavor?

I have already read this guide but it doesn't mention anything that does what I want.

2

There are 2 answers

2
anatoli On BEST ANSWER

just define in app/build.gradle some property for each build type

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

after synchronization you can request if(BuildConfig.UPDATE_ENABLED) and there check for update

0
Asaf On

Google Play checks update availability with your package name. If you use a different package name than the one in the store, the in-app-update update check result will be false.

buildTypes {
        getByName("debug") {
            applicationIdSuffix = ".debug"
            ...
        }
}

OR:

buildTypes {
        debug {
            applicationIdSuffix = ".debug"
            ...
        }
}