为什么在我的 3D Unity 项目中,In App Update 无法在发布模式下工作?

Why In App Update is not working in release mode in my 3D Unity project?

提问人:Tomas Menniti 提问时间:11/16/2023 最后编辑:egleaseTomas Menniti 更新时间:11/16/2023 访问量:17

问:

描述:

我用 Unity 制作的游戏 (2022.3.12f1) 在 Google Play 商店中,并且已实现“应用内更新”。

问题:

当我在 Play 商店中将我的游戏更新到较新版本时,我的旧版本没有显示“新版本可用”弹出窗口。但是,如果我在开发.apk中播放的版本低于PlayStore,我能够看到UPDATE弹出窗口

问题:

为什么它只在开发中工作?

我的代码:

此“InAppUpdate”脚本附加到主场景中的空游戏对象。

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

public class InAppUpdate : MonoBehaviour
{
    AppUpdateManager appUpdateManager;

    void Start()
    {
      appUpdateManager = new AppUpdateManager();
      StartCoroutine(CheckForUpdate());
    }

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

      // Wait until the asynchronous operation completes.
      yield return appUpdateInfoOperation;

      if (appUpdateInfoOperation.IsSuccessful)
      {
        var appUpdateInfoResult = appUpdateInfoOperation.GetResult();
        // Creates an AppUpdateOptions defining an immediate in-app-update flow and its parameters.
        var appUpdateOptions = AppUpdateOptions.ImmediateAppUpdateOptions();

        StartCoroutine(StartImmediateUpdate(appUpdateInfoResult, appUpdateOptions));
      }
    }

    IEnumerator StartImmediateUpdate(AppUpdateInfo appUpdateInfoResult, AppUpdateOptions appUpdateOptions)
    {
      // Creates an AppUpdateRequest that can be used to monitor the
      // requested in-app update flow.
      var startUpdateRequest = appUpdateManager.StartUpdate(
        // The result returned by PlayAsyncOperation.GetResult().
        appUpdateInfoResult,
        // The AppUpdateOptions created defining the requested in-app update
        // and its parameters.
        appUpdateOptions);
      yield return startUpdateRequest;

      // If the update completes successfully, then the app restarts and this line
      // is never reached. If this line is reached, then handle the failure (for
      // example, by logging result.Error or by displaying a message to the user).
    }
}

错误:

异常:找不到字段 currentActivity 或类型签名 UnityEngine._AndroidJNIHelper.GetFieldID (System.IntPtr jclass, System.String fieldName, System.String signature, System.Boolean isStatic) (at :0) UnityEngine.AndroidJNIHelper.GetFieldID (System.IntPtr javaClass, System.String fieldName, System.String signature, System.Boolean isStatic) (at :0) UnityEngine._AndroidJNIHelper.GetFieldID[ReturnType] (System.IntPtr jclass, System.String fieldName, System.Boolean isStatic) (在:0) UnityEngine.AndroidJNIHelper.GetFieldID[FieldType] (System.IntPtr jclass, System.String fieldName, System.Boolean isStatic) (在 :0) UnityEngine.AndroidJavaObject._GetStatic[FieldType] (System.String fieldName) (在 :0) UnityEngine.AndroidJavaObject.GetStatic[FieldType] (System.String fieldName) (在 :0) Google.Play.Common.UnityPlayerHelper.GetCurrentActivity () (在 Assets/GooglePlayPlugins/com.google.play.common/Runtime/Scripts/UnityPlayerHelper.cs:32)Google.Play.AppUpdate.Internal.AppUpdateManagerPlayCore..ctor () (位于 Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/Internal/AppUpdateManagerPlayCore.cs:34) Google.Play.AppUpdate.Internal.AppUpdateManagerInternal..ctor () (位于 Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/Internal/AppUpdateManagerInternal.cs:35) Google.Play.AppUpdate.AppUpdateManager..ctor () (位于 Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/AppUpdateManager.cs:33) InAppUpdate.Start () (位于 Assets/Scripts/InAppUpdate.cs:14)

我尝试使用我的脚本(如上所示的代码)。InAppUpdate

unity-game-engine google-play 应用内更新

评论


答: 暂无答案