46

I have just released an app with in-app billing. So far no crashes have been reported to google play (this only happens when the user takes the trouble to report the crash) but I do have some reports of crashes via flurry (which is automatic). The crash reports are as follows:

class java.lang.RuntimeException
Msg: android.app.ActivityThread.performDestroyActivity:3655 (Unable to destroy activity {com.mycompany.mygame/com.mycompany.mygame.Splashscreen}: java.lang.IllegalArgumentException: Service not registered: com.mycompany.mygame.util.IabHelper$1@46369b38)

This only happens on < 1% of executions of my app.

Correct me if I'm wrong, but it appears that the line number of the crash is not given in the flurry report :-(

I'm not even sure what this crash report means, let alone how to fix it. Any ideas?

Mick
  • 8,284
  • 22
  • 81
  • 173
  • I have the same problem. It is not a BIG deal, but it is something that bothers. I found a similar problem in github: https://github.com/ianhanniballake/ContractionTimer/commit/b3643e8fd1d59a508fe6764398cb22de671c4cea Do you think this might be the same problem? – gian1200 Apr 01 '13 at 21:14
  • The reason why this crash happens now so often is because it can only be reproducible when the InApp billing helper did not set up properly. This will only happen in devices with a very old version of Google Play app of with no Google Play App at all (Kindle Fire) – GaRRaPeTa Aug 07 '13 at 11:44
  • @GaRRaPeTaAbsolutely true. Just loaded up API level 16 on a real device, and boom, crashed on the first screen :) – IcyFlame Jul 14 '16 at 06:24

1 Answers1

117

I believe this is a bug in IabHelper.java.

In IabHelper dispose method, the following line,

            if (mContext != null) mContext.unbindService(mServiceConn);

should be changed to this.

            if (mContext != null && mService != null) mContext.unbindService(mServiceConn);

mService is only set once the Service has been registered, so checking it for != null will guarantee that service is indeed registered, before we try to unbind from it.

therealsachin
  • 1,684
  • 1
  • 14
  • 9
  • 19
    The whole IabHelper is extremly buggy. Should be reimplemented. – tmanthey Aug 05 '13 at 21:26
  • 4
    @tmanthey: is there some alternative non-buggy code we can look at instead? – Mick Jan 09 '14 at 09:26
  • I got a very similar crash recently, and yet the code looks like what you wrote. How could it be? – android developer Mar 10 '15 at 17:20
  • @androiddeveloper Not sure, but if you made the fix recently an old apk with the bug could very well still cause this. – therealsachin Mar 12 '15 at 04:55
  • @therealsachin No, it wasn't recently, and I don't even remember if it was me who did it or if the code was like that before. Weird thing is that it occurred only to a single user, or only he bothered to report, but that's unlikely since I have already plenty of users. I've added a try-catch and it seems to "fix" it, but I don't think it's a good way to solve it. – android developer Mar 12 '15 at 08:35
  • This does come late, but [here](http://stackoverflow.com/a/40793010/6296561) is an answer that covers implementing IAB v3 without IabHelper and the terrible Trivial Drive library. Android Documentation is really vague and doesn't explain it very well, so I tried IabHelper too, but it is one massive bug launcher. Whatever you try to do, there is a crash or error somewhere – Zoe Apr 02 '17 at 08:23