Update to Billing Library 4(sdkbox)

Hi @chuoihottieu, are you sure you haven’t changed anything else in your update? From your logs it is hard to say what is going on.

@bluewind00 Thanks for sharing, it is a very good “base” for the future improvements. Please make it public again :slight_smile:

@PCCSOARES
@kds

Thanks.
I make it public the repository again.
Again, this is a sample and is not guaranteed to work.

2 Likes

hi @kds @bluewind00
i replace sdkbox::IAP with mingos::IAP follow the instructions, it’s work perfert on device support native arm64-v8a, but crash on armeabi-v7a without reason.
for example Samsung Galaxy A13 5G: ABI support: armeabi-v7a, armeabi.
Anyways thanks you guys atleast i upgraded to billing v4 before 1.11.2022!

chuoihottieu
Just replace
PROP_APP_ABI=arm64-v8a
with
PROP_APP_ABI=armeabi-v7a:arm64-v8a
in ‘proj.android\gradle.properties’

bluewind00, thank you very much a lot (you are our hero); I’ve updated your code a bit, to get quantity of purchased products; it works even on Android 4.4.2. (debug and release)

…Now I will try to insert it into my project (seems not so easy).

These are files that can be copied directly into your project.

C++:

Classes/common/JsonParser.cpp
Classes/common/JsonParser.h
Classes/dropbox/json11/json11.cpp
Classes/dropbox/json11/json11.hpp
Classes/iap/MingosIAP.h
Classes/platform/android/Java_iap_PurchaseEventListener.cpp
Classes/platform/android/MingosIAP.cpp

Java:

proj.android/app/src/iap/Product.java
proj.android/app/src/iap/PurchaseEventListener.java
proj.android/app/src/iap/PurchaseManager.java

Next is a set of files that may conflict with your project’s code.
Please incorporate the necessary parts of your project.

proj.android/app/src/org/cocos2dx/cpp/AppActivity.java
proj.android/build.gradle
proj.android/app/build.gradle
proj.android/app/proguard-rules.pro
2 Likes

After two days of crashes and black screens, at last seems I used you code. It was hard (for me), because:

  1. I used separate object (in my c++ code):

sdkbox::IAP::setListener(m_IAP_obj); // m_IAP_obj class extends : sdkbox::IAPListener

And you use the main class for the listener (object) :

class SampleScene : public cocos2d::Scene, public mingos::IAPEventListener { // your code
class HelloWorld : public cocos2d::Layer // my past code

  1. Also there are tiny difference in:

proj.android\app\src\org\cocos2dx\cpp\AppActivity.java
:
public class AppActivity extends Cocos2dxActivity { // your code
public class AppActivity extends com.sdkbox.plugin.SDKBoxActivity { // my code

mPurchaseManager = new PurchaseManager(this); // is it possible to change this file to use as listener not AppActivity class (object), but something else?

Thank you for your great job! :slight_smile: Thanks to you, maybe our Cocos games will be alive for some more time.

1 Like

This is a very important point, but in order to create your own purchase process, you must leave the sdkbox.
This means applying the following code to AppActivity.

public class AppActivity extends Cocos2dxActivity { 

If you apply my code as it is below, you will not receive the notification after the purchase request with my code.
This is because SDKBoxActivity will receive the result of the process from the store.

public class AppActivity extends com.sdkbox.plugin.SDKBoxActivity 

In other words, leaving the code above is not an option for us.

mPurchaseManager = new PurchaseManager(this); // is it possible to change this file to use as listener not AppActivity class (object), but something else?

Are you saying you want to minimize changes to AppActivity?
Then you can do that by making PurcahaseManager a singleton.
If the intent of this question is to keep the following code as explained earlier, it makes no sense.

public class AppActivity extends com.sdkbox.plugin.SDKBoxActivity 

I have changed PurcahseManager to singleton in my latest code.

1 Like

Strange, but it works…

Thank you! :slight_smile:

Hi @bluewind00 ,

Thank you for your great job. You have saved my project :smiley:

For those who get mingos::IAP to work by installing the game from Android Studio, but it crashes if you install it from APK… DON’T FORGET TO ADD THESE LINES TO YOUR proguard-rules.pro:

-keep class iap.** { ; }
-dontwarn iap.
*

:person_facepalming:

1 Like

just update recently one of my games to billing library 4, with this sample and it’s working great.
the only odd thing, is that sometimes I get these crashes:

Crashed: Thread: SIGSEGV  0x0000000000000000
#00 pc 0x175f30  (std::__ndk1::__function::__func<Java_iap_PurchaseEventListener_onInitialized::$_1, std::__ndk1::allocator<Java_iap_PurchaseEventListener_onInitialized::$_1>, void ()>::operator()() [Java_iap_PurchaseEventListener.cpp:76])
#01 pc 0x40ec34 (cocos2d::Scheduler::update(float) [functional:1867])
#02 pc 0x3f7d0c (cocos2d::Director::drawScene() [CCDirector.cpp:264])
#03 pc 0x3fa14c (cocos2d::Director::mainLoop() [CCDirector.cpp:1392])

line 76 is:

listener->onInitialized(success);

not sure if we should add a try catch there for the case of the listener not being present anymore…
or maybe its something else. any ideas?

I’m very grateful for your generosity in releasing this code. Does anyone have any thoughts on the best way to make use of it within a lua-based app?

I’m thinking either hack the lua wrappers that are supplied with sdkbox, or create a replacement sdkbox:IAP class that calls into this new code where possible and stubs anything that isn’t supported. I’m unsure what’s best though, so interested in what others with more experience with Android think.

Hmmm, I’m obviously not as smart as I hoped I was! :slight_smile: I’m struggling to understand how to make use of this in an existing cocos2d-x project, of either type - cpp or lua. I imagined if I stared at the instructions for long enough that it would become clear, but it’s not happening. This looks to be a standalone sample. So, is there an easy way to determine exactly which files need to be copied into an existing project and which files within the existing project need tweaking?

Sorry, ignore me: I can now see that more detailed instructions appear in this thread.

sdkbox’s implementation doesn’t seem to include an acknowledge method. Is that because acknowledging was handled automatically internally to the library? With the new code, do we now need to acknowledge purchaces?

acknowledge seems to be a new API that appeared in v4.
Since sdkbox only handles up to Google Play Billing Library v3, acknowledge does not exist in the first place.

After receiving a purchase completion response from Google Play, you must issue a request to Google Play corresponding to the type of item.

Consumable item => consume
Non-consumable item => acknowledge

In the sample code, the following part corresponds to this

// Classes/scene/SampleScene.cpp
void SampleScene::onPurchaseSuccess(const mingos::Product& product) {
    CCLOG("SampleScene::onPurchaseSuccess: product=%s", product.toJson().dump().c_str());

    if(product.type == mingos::IAP_Type::CONSUMABLE) {
        mingos::IAP::consume(product.id);
    } else if (product.type == mingos::IAP_Type::NON_CONSUMABLE) {
        mingos::IAP::acknowledge(product.id);
    }

    ...
}
1 Like

I got error like you! Any idea for this?

bluewind00 – I’ve been trying to get things to build, but keep getting different build errors, depending on how I set it up. Are you able to tell me the versions of various components that were used when building with the files in mingos/cocos2d-andriod-iap-sample from github? I think recent recent updates to various tools may be incompatible with this project, but if I install legacy tools maybe it will work. So, what were the exact versions you used for: cocos2d-x, NDK, Android Studio, and gradle?

Please review the steps for each STEP.
There must be a mistake in the configuration.
I have confirmed that I can build with the latest Android Studio.
Have you already released a game that implements in-app purchases with cocos2d-x and sdkbox?
If so, you should know what you need to set.

Anyone found any problems moving to billing 5 or billing 6.