PeterStaev / nativescript-purchase

:moneybag: A NativeScript plugin for making in-app purchases!
Apache License 2.0
82 stars 28 forks source link

Cannot read property 'getIntExtra' of null #46

Closed RoyiNamir closed 6 years ago

RoyiNamir commented 6 years ago

Ok. I've uploaded an app to google play store and in the pre tests , I got an error :

FATAL EXCEPTION: main
Process: org.royinamir.playwithpinky, PID: 12219
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4590, result=0, data=null} to activity {org.royinamir.playwithpinky/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onActivityResult failed
TypeError: Cannot read property 'getIntExtra' of null
File: "file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js, line: 1, column: 410904
StackTrace: 
    Frame: function:'', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 410905
    Frame: function:'e.notify', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 445959
    Frame: function:'e.onActivityResult', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 376149
    Frame: function:'r.onActivityResult', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 1084595
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4750)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4793)
    at android.app.ActivityThread.access$1500(ActivityThread.java:218)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1783)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6934)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: com.tns.NativeScriptException: 
Calling js method onActivityResult failed
TypeError: Cannot read property 'getIntExtra' of null
File: "file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js, line: 1, column: 410904
StackTrace: 
    Frame: function:'', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 410905
    Frame: function:'e.notify', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 445959
    Frame: function:'e.onActivityResult', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 376149
    Frame: function:'r.onActivityResult', file:'file:///data/data/org.royinamir.playwithpinky/files/app/vendor.js', line: 1, column: 1084595
    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
    at com.tns.Runtime.callJSMethod(Runtime.java:970)
    at com.tns.Runtime.callJSMethod(Runtime.java:954)
    at com.tns.Runtime.callJSMethod(Runtime.java:946)
    at com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:80)
    at android.app.Activity.dispatchActivityResult(Activity.java:6867)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4746)
    ... 10 more
Error reporting crash
java.lang.SecurityException: Calling from not trusted UID!
    at android.os.Parcel.readException(Parcel.java:1546)
    at android.os.Parcel.readException(Parcel.java:1499)
    at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:5193)
    at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:95)
    at com.tns.NativeScriptUncaughtExceptionHandler.uncaughtException(NativeScriptUncaughtExceptionHandler.java:64)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
    at android.support.test.runner.MonitoringInstrumentation$3.uncaughtException(MonitoringInstrumentation.java:8)

searched who activate this method :

image

Finding the method and the line :

image

led me to the plugin code :

image

for some reason this :

var intent = args.intent; is null on some callbacks.

PeterStaev commented 6 years ago

Hey @RoyiNamir , thanks for this, but i want a bit more info when does this happen, before I merge this. In my tests i have never received the intent to be null. Are you sure you followed the set up in the tutorials? Also in what cases did you get the intent to be null?

I do not want to merge this and "mask" a possible user error.

RoyiNamir commented 6 years ago

@PeterStaev Sure I will give you full details. Just bare with me :

This is the EXACT code I'm using in my app : https://gist.github.com/RoyiNamir/82d6ad32cca946a4c84bd53a3c51f974

It's a service ( like i've posted here before , of all API promisified).

And this is how I consume it : https://gist.github.com/RoyiNamir/a0033d1438fb306b10956eeae502b36a

Please notice that test failed only in a certain device from google tests :

image

Where my version was 15.

And this is the exact error I provided : image

On an earlier version , it happened in another device :

image

Now i'm at version 16 ,after the fix :

image

BTW , it's not that I've changed the flow. Programatically speaking , a property can be null. and if it can be null , we should see how we deal with it.

I don't know why activity was null I can think of some thoughts:

The code doesn't clean the purchas.on method callback. Also , the user might have been minimizing the app while callback was running . , and you don't check if activity exists on callback. this is the exact PR I did in eddy's code , to check activity on callback :

https://github.com/EddyVerbruggen/nativescript-admob/commit/f0487b321fb8a70952fa125949bc7fca3fb9d7ac

PeterStaev commented 6 years ago

Ok, after further search, seems it is a random error from Google. It does not relate to activity whatsoever since the code does not use the activity. after the purchase has been made and the intent data is what Google returns from purchase. So probably more like a problem contacting the Google services.

I will see to add your code, but will rewrite it since I don't like the multiple checks for the intent.

RoyiNamir commented 6 years ago
PeterStaev commented 6 years ago

Changes have been added with c2a8b22