Got a nullpointer exception with IAP on android device

Got a nullpointer exception with IAP on android device
0

#1

I just got 2 android vital reports for a null exception. Anyone have a clue what I could do different? This seems to be happening on the init. It is obviously not happening all the time, just randomly. Probably less than 1% startup.

I have the IAP 2.4.0.3 on cocos2d-x 3.17

Here is the trace:

java.lang.NullPointerException :

at com.android.billingclient.api.BillingClientImpl.querySkuDetailsAsync (BillingClientImpl.java:408)

at com.sdkbox.plugin.SDKBoxIABBillingClient.onSkuDetailsResponse (SDKBoxIABBillingClient.java:566)

at com.android.billingclient.api.BillingClientImpl$2$1.run (BillingClientImpl.java:434)

at android.os.Handler.handleCallback (Handler.java:808)

at android.os.Handler.dispatchMessage (Handler.java:103)

at android.os.Looper.loop (Looper.java:193)

at android.app.ActivityThread.main (ActivityThread.java:5398)

at java.lang.reflect.Method.invokeNative (Native Method)

at java.lang.reflect.Method.invoke (Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:940)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:756)

at dalvik.system.NativeStart.main (Native Method)


#2

Thanks for your vital report.


#3

I’ve got another one. Is there any way to prevent this? Is there some checks I have to do on my side to prevent something like this?

Report 1 of 1

java.lang.ArrayIndexOutOfBoundsException :

at java.util.ArrayList.remove (ArrayList.java:486)

at com.sdkbox.plugin.SDKBoxIABBillingClient.requestProducts (SDKBoxIABBillingClient.java:170)

at com.sdkbox.plugin.IAPWrapper.nativeOnInitialized (Native Method)

at com.sdkbox.plugin.IAPWrapper.access$000 (IAPWrapper.java:9)

at com.sdkbox.plugin.IAPWrapper$1.run (IAPWrapper.java:26)

at android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1507)

at android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1267)


#4

how do you use IAP api ?


#5

I do init from the appdelegate: sdkbox::IAP::init();

And then I call sdkbox::IAP::refresh(); whenever someone open the shop page.

That’s about it. It does happen rarely and does not seem to be related to a specific device model or android version. So far I received 3 crash reports in requestproduct and 2 in onskudetailsresponse in 10 days. It did not happen on IOS.


#6

we have a fixed jar for this issue. could you plz help to test it ?

PluginIAP.jar.zip (25.3 KB)

Thanks,


#7

Ok thanks. I will take a look. It might take a few days to implement and submit and a few weeks to validate. I will write back here around mid-January (or before if I find something)


#8

I am running into issues that are unrelated to the original issue of this post. Not sure if I need to create a new post but anyway if you have an idea:

I tried to copy the JAR you gave me, but it seems I needed the latest versions of SDKBOX plugins. So I updated them via the SDKbox-GUI and all went well. IOS build fine with the new updated version, however I cannot get the android to build (with the official JARs, not the one you gave me). Regardless what I do I get either compile error or some errors that say Program type already present.

It seems the newer version is using a new place to store the jar: proj.android\app\libs. While the previous version used cocos2d\cocos\platform\android\java\libs. So I endup with the old JARs in one place and the new JARs in another place. I tried to removed them from one place, I get compile error as it cannot solve import com.sdkbox.plugin.SDKBox. I tried having them at both places and I get link error:

Error: Program type already present: com.android.billingclient.api.BillingBroadcastManager$BillingBroadcastReceiver

I am kind of stuck at the moment. Regardless of my original crash issues, I just cannot make the newer version of SDKBox plugins to compile on android.

******EDIT *****
From another post, I saw that I now had a depedency on billing:1.0 added in the gradle script. So I removed the JAR of this lib and resolved this issue. I then removed all plugin JARs from one place and kept them at the new directory except sdkbox.jar since I need it in both place to compile it seems… I end up with one new duplicate dependency:

Error: Program type already present: com.sdkbox.adbooster.AdBooster

EDIT 2*
Seems like I really need to put all in the new directory. I end up with the compile error where my cocos2dxactivity java file cannot resolve import com.sdkbox.plugin.SDKBox

EDIT 3*

So I was able to make it compile and I tested and everything seems to be working. Had to do multiple modifications

sdkbox.jar is within the folder: cocos2d\cocos\platform\android\java\libs
Other plugin jars are within proj.android\app\libs
I replaced the original IAPplugin with yours
changed AppActivity extends from com.sdkbox.plugin.SDKBoxActivity to Cocos2dxActivity
Removed android-support-v4.jar, support-annotations-27.1.1.jar and billing-1.0.jar since they were duplicate.
removed the depedency in the gradle file for com.google.android.gms:play-services-ads:15.0.1

I can’t believe I really needed to do all this. I guess a lot of legacy jars and dependencies. However, the fact that I cannot make it work with the extends sdkboxActivity and only work with the base cocos2dxActivity has me a little worried. However, everything seems to be working fine. Not sure what it does with or without.

I will let you know if I see more crashes.


#9

We are sorry for the inconvenience.

It seems that the way you integrate sdkbox is still old. Of course, this is also caused by us. At the beginning of a certain version, sdkbox recommends:

  1. All third-party files are placed in the user’s development directory, such as /proj.android
  2. Restore the cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java file to the engine default state.
  3. proj.android/app/src/org/cocos2dx/cpp/AppActivity.java extends from com.sdkbox.plugin.SDKBoxActivity.

The automation of this part of the work sdkbox is not done yet, we will fix this problem as soon as possible.

sorry again.


#10

So far so good on the bug. I just got a new bug though. It happened 5 time in the same minute for 1 user:

#00 pc 0000000000018436 /system/lib/libc.so (strcpy+1)

#01 pc 000000000020f185 /data/app/com.bewgames.survivaladventure-1/lib/arm/libMyGame.so (_ZN9c_Billing23onProductRequestSuccessERKNSt6__ndk16vectorIN6sdkbox7ProductENS0_9allocatorIS3_EEEE+356)

#02 pc 00000000002148ef /data/app/com.bewgames.survivaladventure-1/lib/arm/libMyGame.so (ZN6sdkbox17IAPWrapperEnabled22onProductRequestResultENS_18ProductRequestCodeEPKcS3+158)

#03 pc 0000000000212005 /data/app/com.bewgames.survivaladventure-1/lib/arm/libMyGame.so (Java_com_sdkbox_plugin_IAPWrapper_nativeOnRequestResult+100)

#04 pc 00000000006ca55b /data/app/com.bewgames.survivaladventure-1/oat/arm/base.odex


#11

Thanks your crash detail. I’ll fix it ASAP.


#12

onProductRequestSuccess is a iap listener event, this is implement by you, can you check your code?


#13

Ok thanks, I just took a look and the only possibility I see is that I received a title without parenthesis. On android, for god knows why, all the titles I receive contains a parenthesis. So instead of getting

75 full heal potions

I receive

75 full heal potions (full_heal_potion_1)

So I remove the parenthesis portion before displaying it. So I guess the title I received had something different. I can certainly prevent the crash, but it would be good to know why I received something different.


#14

title is get from SkuDetails.

i tried with our sample, get title

Bag of coins (IAP Test)

this seem like app name.