IN APP UPDATE (UNITY) : Exception: Field currentActivity or type signature not found

Viewed 530

I am getting the following error message when my code executes:

Exception: Field currentActivity or type signature not found 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) (at :0) UnityEngine.AndroidJNIHelper.GetFieldID[FieldType] (System.IntPtr jclass, System.String fieldName, System.Boolean isStatic) (at :0) UnityEngine.AndroidJavaObject._GetStatic[FieldType] (System.String fieldName) (at :0) UnityEngine.AndroidJavaObject.GetStatic[FieldType] (System.String fieldName) (at :0) Google.Play.Common.UnityPlayerHelper.GetCurrentActivity () (at Assets/GooglePlayPlugins/com.google.play.common/Runtime/Scripts/UnityPlayerHelper.cs:32) Google.Play.AppUpdate.Internal.AppUpdateManagerPlayCore..ctor () (at Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/Internal/AppUpdateManagerPlayCore.cs:34) Google.Play.AppUpdate.Internal.AppUpdateManagerInternal..ctor () (at Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/Internal/AppUpdateManagerInternal.cs:35) Google.Play.AppUpdate.AppUpdateManager..ctor () (at Assets/GooglePlayPlugins/com.google.play.appupdate/Runtime/Scripts/AppUpdateManager.cs:33) inAppUpdate+d__2.MoveNext () (at Assets/____Script/IN APP UPDATE/inAppUpdate.cs:18) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) inAppUpdate:Start() (at Assets/____Script/IN APP UPDATE/inAppUpdate.cs:13)

The code in question is:

public class inAppUpdate : MonoBehaviour
{
    AppUpdateManager appUpdateManager;

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

    IEnumerator CheckForUpdate()
    {
        AppUpdateManager appUpdateManager = new AppUpdateManager();

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

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

        if (appUpdateInfoOperation.IsSuccessful)
        {
            var appUpdateInfoResult = appUpdateInfoOperation.GetResult();
            var appUpdateOptions = AppUpdateOptions.ImmediateAppUpdateOptions();
            // Check AppUpdateInfo's UpdateAvailability, UpdatePriority,
            // IsUpdateTypeAllowed(), etc. and decide whether to ask the user
            // to start an in-app update.
            StartCoroutine(StartImmediateUpdate(appUpdateInfoResult, appUpdateOptions));
        }
        else
        {
            // Log appUpdateInfoOperation.Error.
        }
    }

    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).
    }

}

Can anyone provide me with assistance in understanding the cause of the error?

1 Answers

Exception: Field currentActivity or type signature not found UnityEngine._AndroidJNIHelper.GetFieldID Same problem here in In-App Updates - Unity

This is my code with check Internet Connection:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Google
using Google.Play.AppUpdate;
using Google.Play.Common;
using UnityEngine.UI;
//Internet Check
using System;
using System.Web;
using System.Net.NetworkInformation;
using UnityEngine.Networking;

public class InAppUpdate : MonoBehaviour
{
    AppUpdateManager appUpdateManager;
    // Start is called before the first frame update
    void Start()
    {
        appUpdateManager = new AppUpdateManager();
        StartCoroutine(CheckInternetConnections(isConnected =>
         {
            if (isConnected)
            {
                Debug.Log("Internet Available!");
                StartCoroutine(CheckForUpdate()); 
            }
            else
            {
                Debug.Log("Internet Not Available");
            }
         }));
    }

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

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

            if(appUpdateInfoResult.UpdateAvailability == UpdateAvailability.UpdateAvailable){
                Debug.Log("Update Available!");
            }else{
                Debug.Log("Update Not Available!");
            }

            var appUpdateOptions = AppUpdateOptions.ImmediateAppUpdateOptions();
            StartCoroutine(StratImmediateUpdate(appUpdateInfoResult, appUpdateOptions));
        }
    }

    IEnumerator StratImmediateUpdate(AppUpdateInfo appUpdateInfo_i, AppUpdateOptions appUpdateOptions_i){
        var startUpdateRequest = appUpdateManager.StartUpdate(appUpdateInfo_i, appUpdateOptions_i);
        yield return startUpdateRequest;
    }
    IEnumerator CheckInternetConnections(Action<bool> action)
    {
        UnityWebRequest request = new UnityWebRequest("http://google.com");
        yield return request.SendWebRequest();
        if (request.error != null) {
            Debug.Log ("Error");
            action (false);
        } else{
            Debug.Log ("Success");
            action (true);
        }
    }
}
Related