Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resolved Unity Iap in-app-puchase 4.9.4 NoSuchMethodError 'initialize'

Discussion in 'Unity IAP' started by Dreamidea2017, Oct 10, 2023.

  1. Dreamidea2017

    Dreamidea2017

    Joined:
    Feb 1, 2019
    Posts:
    6
    I updated Unity Iap in-app-puchase 4.4.1 to 4.9.4. because billing version 4 -> 5.
    Unity Editor Version is 2021.3.10f1
    but I have Problem.
    This is android log cat.
    java.lang.NoSuchMethodError: no non-static method with name='initialize' signature='(Landroid.app.Application;Lcom.android.billingclient.api.PurchasesUpdatedListener;Z)V' in class Ljava.lang.Object;


    and I found that here is problem
    Code (CSharp):
    1.             UnityPurchasing.Initialize(this, builder);
    If I use billing version 4, there is no bug, but if I use version 5, there is a bug.
     
  2. jawnwee

    jawnwee

    Joined:
    Nov 4, 2019
    Posts:
    31
    Make sure your main class is inheriting from IDetailedStoreListener

    using UnityEngine.Purchasing;
    using UnityEngine.Purchasing.Extension;

    You'll also need to fix
    void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription);
     
  3. Dreamidea2017

    Dreamidea2017

    Joined:
    Feb 1, 2019
    Posts:
    6
    Thanks for the reply.
    but bug again...

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Purchasing;
    5. using UnityEngine.Purchasing.Security;
    6. using System;
    7. using Gaa;
    8. using UnityEngine.Purchasing.Extension;
    Code (CSharp):
    1. public class IAPManager : Singleton<IAPManager>, IDetailedStoreListener
    2.  
    and I fixed
    Code (CSharp):
    1. public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    2.     {
    3.         if (p == PurchaseFailureReason.PurchasingUnavailable)
    4.         {
    5.             // IAP may be disabled in device settings.
    6.         }
    7.     }
    8.     public void OnPurchaseFailed(Product i, PurchaseFailureDescription p)
    9.     {
    10.         RestoreButtonClick();
    11.  
    12.  
    13.         Debug.Log(p.ToString());
    14.         if (p.reason == PurchaseFailureReason.DuplicateTransaction)
    15.         {
    16.             try
    17.             {
    18.                 ResetrTransaction();
    19.             }
    20.             catch....................................

    java.lang.NoSuchMethodError: no non-static method with name='initialize' signature='(Landroid.app.Application;Lcom.android.billingclient.api.PurchasesUpdatedListener;Z)V' in class Lcom.android.billingclient.api.BillingClientImpl;


    java.lang.NoSuchMethodError: no non-static method with name='initialize' signature='(Landroid.app.Application;Lcom.android.billingclient.api.PurchasesUpdatedListener;Z)V' in class Ljava.lang.Object;
     
  4. jawnwee

    jawnwee

    Joined:
    Nov 4, 2019
    Posts:
    31
    Whats your builder look like?

    Code (CSharp):
    1.  
    2. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    3. UnityPurchasing.Initialize(this, builder);
    4.  
     
  5. Dreamidea2017

    Dreamidea2017

    Joined:
    Feb 1, 2019
    Posts:
    6
    my builder is

               
    var module = StandardPurchasingModule.Instance();
    ConfigurationBuilder builder = null;
    #if UNITY_ANDROID && !UNITY_EDITOR

    //## android is here ##

    if (Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay)
    {
    builder = ConfigurationBuilder.Instance(Google.Play.Billing.GooglePlayStoreModule.Instance());
    m_IsGooglePlayStoreSelected = true;
    }
    #else
    builder = ConfigurationBuilder.Instance(module);

    /*m_IsCloudMoolahStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.CloudMoolah;
    m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps;*/
    m_IsGooglePlayStoreSelected = false;
    #endif
    for (int i = 0; i < Item_Production_ID.Count; i++)
    {
    builder.AddProduct(Item_Production_ID[i], UnityEngine.Purchasing.ProductType.Consumable, new UnityEngine.Purchasing.IDs
    {
    { Item_Production_ID[i], AppleAppStore.Name },
    { Item_Production_ID[i], GooglePlay.Name},
    });
    }
    Debug.Log(builder.products);
    Debug.Log("## Initialize ~~ ##");
    Debug.Log("this : " + this + "/// builder : " + builder);
    UnityPurchasing.Initialize(this, builder);
    Debug.Log("## Initialize success~~ ##");
     
  6. jawnwee

    jawnwee

    Joined:
    Nov 4, 2019
    Posts:
    31
    Try removing this part as this is whats overriding your builder see: https://docs.unity3d.com/Packages/com.unity.purchasing@4.9/manual/UnityIAPInitialization.html

    Code (CSharp):
    1.  
    2. if (Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay)
    3.             {
    4.  
    5.                 builder = ConfigurationBuilder.Instance(Google.Play.Billing.GooglePlayStoreModule.Instance());
    6.  
    7.                 m_IsGooglePlayStoreSelected = true;
    8.  
    9.             }
    10.  
    If a unity dev is reading, would appreciate you guys being a bit more active to bug posts here.
     
    Dreamidea2017 likes this.
  7. Dreamidea2017

    Dreamidea2017

    Joined:
    Feb 1, 2019
    Posts:
    6
    I really appreciate your answer. The bug has been resolved. There are still a few more parts to fix, but payment is now possible.

                    //builder = ConfigurationBuilder.Instance(Google.Play.Billing.GooglePlayStoreModule.Instance());
    builder = ConfigurationBuilder.Instance(module);

    I fixed here and resolve the problem.
    this("Google.Play.Billing.GooglePlayStoreModule.Instance") is problem.
    thank you so much.