Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload Android and Android TV APK to Google Play via Google Play API

Background

Android application has 2 version: 1 for mobile devices, 1 for Android TV.
Android TV APK version code should be significantly higher than mobile devices Android APK version code.
APK for mobile devices has version codes like 10, 11, 12, etc.
APK for Android TV devices has version codes like 10001, 10010, etc.

Since both these APK's are published via one app configuration in Google Play, we have "shared" alpha/beta tracks. And when we release we just retain multiple APK's (1 for TV and 1 mobile devices).

I want to upload APK to Google Play alpha/beta track using Google Play API either using Gradle plugin or Jenkins plugin.
It doesn't matter which approach I'm choosing, I'm getting an error when I'm trying to upload APK for mobile devices.

Upload failed: - Devices with version 10002 of this app would be downgraded to version 54 if they met the following criteria: [(API_LEVEL in range 19-0 AND RELEASE_TRACK containing any of each of [[BETA]] AND SCREENS containing any of each of [[small, normal, large, xlarge]] AND NATIVE_PLATFORM containing any of each of [[x86_64, x86, armeabi-v7a, arm64-v8a]] AND GL_ES_VERSION in range 131072-0 AND FEATURES containing all of [android.hardware.screen.portrait, android.software.leanback, android.hardware.faketouch])].

This error clearly says that I can't upload APK with 54 version code (mobile device) since APK with 10002 version code (Android TV) is already in Google Play.
But Google Play allows me to accomplish this manually (through Google Play console UI) - create beta release with APK (54 version code) and retain existing APK in beta (10002 version code).

Question

Is it possible to upload APK for mobile device and for Android TV devices through Google Play API?
Is there any way to upload APK for mobile device to alpha/beta track and automatically retain APK from alpha/beta track which was there before upload?

like image 390
Veaceslav Gaidarji Avatar asked Mar 14 '18 16:03

Veaceslav Gaidarji


People also ask

How do I publish my Android TV app?

Add TV screenshots and banner graphic to the app's store listing. In the All Applications page, click the app you want to opt-in. Under Pricing and Distribution, scroll down to find Android TV and the opt-in checkbox. Click the checkbox next to Distribute your app to Android TV.


1 Answers

At first i would suggest giving the Mobile app a version number in the same number range as in the Tv app - Example:

// map for the version code
    project.ext.versionCodes = ['tv': 1, 'mobile': 2]
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.versionCodeOverride =
                    project.ext.versionCodes.get(output.getFilter(
                            com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode
        }
    }

As users will always get the higher version number vended to them you need the higher version number will have the criteria for the mobile devices and the lower version is a fallback to all devices that failed to qualify. You can also create specific flavours if a bit more grained control is needed. I'm using splits based on ABI as well as using Triple-T plugin for that matter and this works for all the versions i deploy.

like image 171
MaTriXy Avatar answered Nov 09 '22 08:11

MaTriXy