Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Google Cardboard IAP crashes

Discussion in 'Unity IAP' started by uygaruyaniksoy, Aug 10, 2017.

  1. uygaruyaniksoy

    uygaruyaniksoy

    Joined:
    May 17, 2017
    Posts:
    1
    Hello,

    I have a simple google cardboard game in Unity 5.6.1 and up to date IAP plugin. When I call 'BuyLevels' function the game crashes. Everything is OK in unity but I get this error on my Android device and can't really figure out what causes the error.

    08-10 17:10:53.150 26357-26422/? I/Unity: OnInitialized: PASS

    (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    08-10 17:10:56.455 26357-26422/? I/Unity: Purchasing product asychronously: 'morelevels'

    (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    08-10 17:10:56.455 26357-26422/? I/UnityIAP: isUnityVrEnabled = true
    08-10 17:10:56.455 26357-26422/? I/UnityIAP: onPurchaseProduct: morelevels
    08-10 17:10:56.455 26357-26422/? I/UnityIAP: ITEM TYPE:inapp
    08-10 17:10:56.455 26357-26422/? I/Unity: purchase({0}): morelevels

    (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    08-10 17:10:56.460 26357-26357/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.uyaniksoy.powerdefencevr, PID: 26357
    java.lang.Error: FATAL EXCEPTION [main]
    Unity version : 5.6.1f1
    Device model : samsung SM-N910C
    Device fingerprint: samsung/treltexx/trelte:6.0.1/MMB29K/N910CXXS2DQGB:user/release-keys

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.vr.ndk.base.DaydreamApi.launchInVr(android.content.Intent)' on a null object reference
    at com.unity.purchasing.googleplay.GooglePlayPurchasing$6.run(GooglePlayPurchasing.java:451)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7225)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

    public class Purchaser : MonoBehaviour, IStoreListener {
    public static Purchaser Instance { set; get; }

    private static IStoreController m_StoreController; // The Unity Purchasing system.
    private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.

    public static string PRODUCT_8_LEVELS = "morelevels";

    void Start() {
    if (m_StoreController == null) {
    InitializePurchasing();
    }
    }
    private void Awake() {
    Instance = this;
    }

    public void InitializePurchasing() {
    if (IsInitialized()) {
    return;
    }
    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    builder.AddProduct(PRODUCT_8_LEVELS, ProductType.NonConsumable);
    UnityPurchasing.Initialize(this, builder);
    }

    private bool IsInitialized() {
    return m_StoreController != null && m_StoreExtensionProvider != null;
    }

    public void BuyLevels() {
    BuyProductID(PRODUCT_8_LEVELS);
    }

    void BuyProductID(string productId) {
    if (IsInitialized()) {
    Product product = m_StoreController.products.WithID(productId);

    if (product != null && product.availableToPurchase) {
    Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    m_StoreController.InitiatePurchase(product);
    }
    else {
    Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    }
    }
    else {
    Debug.Log("BuyProductID FAIL. Not initialized.");
    }
    }

    public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
    Debug.Log("OnInitialized: PASS");
    m_StoreController = controller;
    m_StoreExtensionProvider = extensions;
    }


    public void OnInitializeFailed(InitializationFailureReason error) {
    Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    }


    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
    if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_8_LEVELS, StringComparison.Ordinal)) {
    Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
    PlayerPrefs.SetInt("boughtLevels", 1);

    foreach (GameObject _lock in GameObject.FindGameObjectsWithTag("lock")) {
    Destroy(_lock);
    }
    GameObject.Find("BuyMoreLevels").transform.GetChild(0).gameObject.GetComponent<UnityEngine.UI.Text>().text = "Thank you!";
    GameObject.Find("BuyMoreLevels").GetComponent<UnityEngine.UI.Button>().interactable = false;

    }
    else {
    Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    }
    return PurchaseProcessingResult.Complete;
    }


    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) {
    Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    }
    }

    Sorry for the horribly long post and thank you for your time.
     
  2. APalomo

    APalomo

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    649
    @uygaruyaniksoy

    Thanks for reporting this. We are looking into our compatibility with Google Cardboard. I apologize for any inconvenience this has caused.