vstirbu / InstagramPlugin

Instagram plugin for PhoneGap/Cordova
MIT License
120 stars 78 forks source link

Plugin Crash #72

Closed rodrigograca31 closed 7 years ago

rodrigograca31 commented 8 years ago

Hi! Great plugin.

I have this app that relys evely on this plugin. I get a lot of people complaining that the app crashes after posting a picture (when they get back to my app).

It seems to happen only on Android 5 or latter... And in Moto G's .... screenshot-area-2016-08-31-000003

My code:

Instagram.share(square.toDataURL(), description, function (err) {
    ...
    if (err) {
        console.log(err);
    }
});

I don't know enought Java to be able to solve this problem but this crash report might help you guys. Let me know if you need more information and thanks!

Crash report:

java.lang.RuntimeException: Unable to resume activity {com.instasquares/com.instasquares.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=0, data=null} to activity {com.instasquares/com.instasquares.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3026)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3061)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    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:947)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=0, data=null} to activity {com.instasquares/com.instasquares.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3646)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3012)
    ... 11 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at com.vladstirbu.cordova.CDVInstagramPlugin.onActivityResult(CDVInstagramPlugin.java:135)
    at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:151)
    at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348)
    at android.app.Activity.dispatchActivityResult(Activity.java:6226)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3642)
    ... 12 more
vstirbu commented 8 years ago

The plugin is lagging behind considering the latest Cordova APIs. What Cordova version are you using and is the behaviour consistent on Android 5 and newer?

rodrigograca31 commented 8 years ago

The latest: 5.2.1

(as of a month ago....)

rodrigograca31 commented 8 years ago

BTW, I have a Moto G with Android 5.1 for testing but it doesn't crash on my Moto G....

vstirbu commented 8 years ago

Can you try to install the plugin from git and give it a try:

cordova plugin add https://github.com/vstirbu/InstagramPlugin.git

rodrigograca31 commented 8 years ago

I'll do that, but keep in mind that I will only be able to give some results in at least a couple weeks.... (Time for the new apk to spread, be used and have some reports...)

rodrigograca31 commented 8 years ago

Just published a new version of the app... Now I need to wait a couple of weeks to see the results... Thanks for the help!

vstirbu commented 7 years ago

Has the situation improved?

rodrigograca31 commented 7 years ago

Apparently not.... (since September has crashes as shown in the image....)

screenshot-area-2016-09-26-121502

rodrigograca31 commented 7 years ago

Apparently it changed line (since you added more lines....)

java.lang.RuntimeException: Unable to resume activity {com.instasquares/com.instasquares.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=0, data=null} to activity {com.instasquares/com.instasquares.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3141)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3172)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2527)
    at android.app.ActivityThread.access$800(ActivityThread.java:167)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5537)
    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:956)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=0, data=null} to activity {com.instasquares/com.instasquares.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3744)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3123)
    ... 11 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.error(java.lang.String)' on a null object reference
    at com.vladstirbu.cordova.CDVInstagramPlugin.onActivityResult(CDVInstagramPlugin.java:141)
    at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:153)
    at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348)
    at android.app.Activity.dispatchActivityResult(Activity.java:6177)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3740)
    ... 12 more

LG G3 Android 5.0

rodrigograca31 commented 7 years ago

Update: I'm not really sure if this problem has been solve because the last "error spike" is from 30 of November: screenshot-area-2016-12-09-183741

But either way I've decided to try to get rid of it by creating a bounty: https://www.bountysource.com/issues/37430564-plugin-crash

Here is the app using the plugin: https://play.google.com/store/apps/details?id=com.instasquares

I'm now using cordova platform add android@6.1.0 and cordova cli 6.4.0

If anyone needs some info please ask and I will provide it...

Thanks to everyone.

rodrigograca31 commented 7 years ago

Hi! @vstirbu and @jcesarmobile and others...

I've increased the value of the of the bounty to a total of 50$ ... https://www.bountysource.com/issues/37430564-plugin-crash

You can grab it if you can solve my problem.... :smile:

Thanks!

mpk2 commented 7 years ago

@rodrigograca31 is that the only call to the plugin that you make?

mpk2 commented 7 years ago

It's hard to tell exactly without being able to easily reproduce the issue. I think it's very likely that it has to do with low memory devices pushing out the plugin activity when under memory pressure and that causing the null pointer exception (described here). If that's the case, then there may be one easy band-aid for this problem.

In CDVInstagramPlugin.java, change onActivityResult to

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            Log.v("Instagram", "shared ok");
                if(this.cbContext != null) {
                  this.cbContext.success();
                }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.v("Instagram", "share cancelled");
                if(this.cbContext != null) {
                  this.cbContext.error("Share Cancelled");
                }

        }
    } 

The real solution seems to involve saving state and executing some more complicated code that won't get fired in the callback. If you're not really dependent on the callback, then this may be largely an unnecessary endeavour.

rodrigograca31 commented 7 years ago

Hi @mpk2

What callback are you talking about?

I'll try to update the app with that code and let you know if the crash stopped ... (in a couple of weeks/one month)

Thanks

mpk2 commented 7 years ago

The Javascript callback in which you log potential errors. If you were to implement the state saving solution suggested by Cordova, the plugin would return the plugin result value to the "resume" Javascript handler, NOT the plugin Javascript callback. You don't have to worry about that if you're just going to implement the above.

However, since Android may be killing the activity, you should try not to rely heavily on your callback if you implement my kludge.

rodrigograca31 commented 7 years ago

@mpk2 I just log it... So I could even remove that...

mpk2 commented 7 years ago

That's fine, but it won't fix underlying problems in the Java code, which would still fire the offending methods without the null check.

Hope that helps!

rodrigograca31 commented 7 years ago

I've just release a new version of the app... Let's see if the problem gets solved... https://play.google.com/store/apps/details?id=com.instasquares

The crash graph as of now: image

rodrigograca31 commented 7 years ago

(the issue seems to be solved...) @mpk2 I was trying to attribute the "bountysource" bounty to you but I think that you need to "ask for it"... Please try to login and click "Get Started" ...

https://www.bountysource.com/issues/37430564-plugin-crash

rodrigograca31 commented 7 years ago

Yes, you have to "ask for it"..... Please do that...

How are claims processed?

When a bounty claim is submitted by a developer, the claim is put into a two week verification period. Backers are notified by email and can then accept or reject the claim.

If all Backers vote to accept the claim, it is processed immediately and the developer is awarded the bounty. If any Backer fails to accept the claim, it remains in the two week waiting period. If any Backer has an issue with the claim, they can reject it. Claims cannot be paid out until the dispute is resolved and the rejected status is lifted.

mpk2 commented 7 years ago

@rodrigograca31 Awesome! Glad I was able to help you out

mpk2 commented 7 years ago

@rodrigograca31 It currently says

You have started working on this issue.

You will be able to claim this bounty as soon as the original issue is marked as closed.

So perhaps you have to re-open and re-close it?

rodrigograca31 commented 7 years ago

Done.... let's also wait a few minutes...

mpk2 commented 7 years ago

👍 No worries 😄

rodrigograca31 commented 5 years ago

I still get quite a few java.lang.NullPointerException from this plugin....

I need to hire someone to fix this for me.... @mpk2 are you free? :smile:

Seems an issue with line 157.....

java.lang.RuntimeException: 
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4008)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4040)
  at android.app.servertransaction.ResumeActivityItem.execute (ResumeActivityItem.java:51)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:145)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:70)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1948)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7045)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:964)
Caused by: java.lang.RuntimeException: 
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4605)
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:3997)
Caused by: java.lang.NullPointerException: 
  at com.vladstirbu.cordova.CDVInstagramPlugin.onActivityResult (CDVInstagramPlugin.java:157)
  at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:159)
  at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:359)
  at android.app.Activity.dispatchActivityResult (Activity.java:7759)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4598)
mattkindy commented 5 years ago

Are you still using this approach ("kludge") I detailed here?

https://github.com/vstirbu/InstagramPlugin/issues/72#issuecomment-271532637

The explicit null check should prevent those errors, despite not being the end all be all. I suspect you had implemented it but perhaps didn't fork it yourself. It really should be included into this repo. There's no reason not to check for null

rodrigograca31 commented 5 years ago

Yeah, seems my issue was exactly that! At some point I lost the "kludge", thanks!

I will send a PR to this repo....

BTW, I'm not that good with Android stuff but: if this plugin opens an activity and the cordova activity gets killed means that the "page" (progress) where the user was on my app gets lost right?

mattkindy commented 5 years ago

It has been a little while since I've worked directly on Cordova, but I think that's right, unless you serialize and save state before it's killed and deserialise once it is revived.

On Fri, Mar 29, 2019, 5:57 AM Rodrigo Graça notifications@github.com wrote:

Yeah, seems my issue was exactly that! At some point I lost the "kludge", thanks!

I will send a PR to this repo....

BTW, I'm not that good with Android stuff but: if this plugin opens an activity and the cordova activity gets killed means that the "page" (progress) where the user was on my app gets lost right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vstirbu/InstagramPlugin/issues/72#issuecomment-477956631, or mute the thread https://github.com/notifications/unsubscribe-auth/AiCvBPVFXYMJNzn3dwtkY9d22vFzB_8Xks5vbfGUgaJpZM4JxEgD .