Unity Ads 和 Google Play 结算库

Unity Ads and Google Play Billing Library

我从 AdMob 切换到 UnityAds,现在我的游戏在玩家尝试购买东西后崩溃。

java.lang.RuntimeException: Error receiving broadcast Intent { act=com.android.vending.billing.PURCHASES_UPDATED flg=0x10 pkg=ru.elvale.amfus (has extras) } in com.android.billingclient.api.zzg@6336d8f
    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable[=11=]$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1560)
    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7403)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
 Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
    at com.unity3d.services.store.gpbl.proxies.PurchaseUpdatedListenerProxy.onPurchasesUpdated(PurchaseUpdatedListenerProxy.java:46)
    at com.unity3d.services.store.gpbl.proxies.PurchaseUpdatedListenerProxy.invoke(PurchaseUpdatedListenerProxy.java:32)
    at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
    at $Proxy4.onPurchasesUpdated(Unknown Source)
    at com.android.billingclient.api.zzg.onReceive(com.android.billingclient:billing@@4.0.0:3)
    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable[=11=]$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1550)
    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 
    at android.os.Handler.handleCallback(Handler.java:883) 
    at android.os.Handler.dispatchMessage(Handler.java:100) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7403) 

我看到了 com.unity3d.services.store.gpbl.proxies.PurchaseUpdatedListenerProxy.onPurchasesUpdated,但我只想使用 UnityAds 来展示广告,未连接分析,如何禁用它?

我向Unity官方支持寻求帮助,我们找到了问题。
问题出在默认情况下启用的 Unity Analytics Collection。

Unity Ads 尝试将数据发送到仪表板。 但是目前Unity Ads使用的是Google Billing Library v3,我的时候是v4,导致提交数据出错。

找到2个解决方案:

  • 在 v3 下重写我的计费代码
  • 在 Monetization 文件夹中禁用 Unity Analytics Collection 到仪表板