DEV Community

Abhishek
Abhishek

Posted on

How to implement immediate in-app updates using Google Play API in Unity?

Hi fellow developers!

I’m working on implementing Google Play In-App Updates in my Unity project, but I’ve hit a roadblock when trying to initiate an immediate update. Despite following the official Play Core documentation, I’m encountering an error related to argument conversion when starting the update process.

Problem:

I'm getting the following error in Unity:

CS1503: Argument 1: cannot convert from 'Google.Play.AppUpdate.AppUpdateType' to 'Google.Play.AppUpdate.AppUpdateOptions'
Enter fullscreen mode Exit fullscreen mode

Objective:

I’m trying to implement an immediate in-app update using the Play Core SDK in Unity without handling any priority, just like in Google’s documentation.

Here’s What I’ve Done So Far:

Here’s my current code setup:

using System.Collections;
using UnityEngine;
using Google.Play.AppUpdate;
using Google.Play.Common;

public class InAppUpdateManager : MonoBehaviour
{
    AppUpdateManager appUpdateManager = new AppUpdateManager();

    private void Start()
    {
        StartCoroutine(CheckForUpdate());
    }

    IEnumerator CheckForUpdate()
    {
        PlayAsyncOperation<AppUpdateInfo, AppUpdateErrorCode> appUpdateInfoOperation = appUpdateManager.GetAppUpdateInfo();
        yield return appUpdateInfoOperation;

        if (appUpdateInfoOperation.IsSuccessful)
        {
            var appUpdateInfo = appUpdateInfoOperation.GetResult();

            // Create update options for immediate update
            var appUpdateOptions = AppUpdateOptions.ImmediateAppUpdateOptions();

            // Attempt to start the update
            var appUpdateRequest = appUpdateManager.StartUpdate(appUpdateInfo, appUpdateOptions);
            yield return appUpdateRequest;
        }
        else
        {
            Debug.LogError("Error fetching update info: " + appUpdateInfoOperation.Error);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Error Details:

The specific error occurs when I try to start the update with:

var appUpdateRequest = appUpdateManager.StartUpdate(appUpdateInfo, appUpdateOptions);
Enter fullscreen mode Exit fullscreen mode

It throws the error:

CS1503: Argument 1: cannot convert from 'Google.Play.AppUpdate.AppUpdateType' to 'Google.Play.AppUpdate.AppUpdateOptions'
Enter fullscreen mode Exit fullscreen mode

My Setup:

  • Unity Version: 2022.3.41f1
  • Google Play Core SDK Version: (2.1.0)
  • I’m focusing on immediate updates only.

What I’ve Tried:

  • I’ve ensured that I’m using the correct namespaces: Google.Play.AppUpdate and Google.Play.Common.
  • Verified my integration of the Play Core SDK in Unity.
  • Tried different variations of passing options but haven’t found a working solution.

Questions:

  1. Is there something I’m missing in how AppUpdateOptions is being set up for immediate updates?
  2. Has anyone encountered this issue with the Play Core SDK in Unity? How did you resolve it?
  3. Is there a better way to handle the immediate update flow for Google Play In-App Updates in Unity?

Thanks in advance!

Any help or suggestions are appreciated. I’m eager to get this working!

Top comments (0)