Skip to content

Commit

Permalink
Fix the problem of release crash on android platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuguohua committed Dec 12, 2024
1 parent 0fec767 commit b2d878f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
2 changes: 2 additions & 0 deletions native/cocos/platform/android/libcocos2dx/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Add any project specific keep options here:
-keep public class com.google.** { *; }
-keep public class com.android.** { *; }
-keep public class google.billing.** { *; }
-keep public class androidx.** { *; }
-keep class com.cocos.lib.CocosActivity {
public <methods>;
Expand Down
62 changes: 59 additions & 3 deletions native/vendor/google/billing/GoogleBilling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cocos/bindings/jswrapper/SeApi.h"
#include "platform/java/jni/JniHelper.h"
#include "platform/java/jni/JniImp.h"
#include "vendor/google/billing/result-values/BillingResult.h"
#include "vendor/google/billing/GoogleBillingHelper.h"
#include "vendor/google/billing/GoogleBillingManager.h"
#include "vendor/google/billing/build-params/AcknowledgePurchaseParams.h"
Expand Down Expand Up @@ -133,12 +134,16 @@ bool BillingClient::isReady() const {
}

void BillingClient::queryProductDetailsAsync(QueryProductDetailsParams* params, se::Object* listener) {
if(!params || !listener) {
CC_LOG_WARNING("params or listener can't be null");
return;
}
int listenerId = addListener(listener);

std::vector<std::string> productIds;
std::vector<std::string> productTypes;
productIds.reserve(16);
productTypes.reserve(16);
size_t size = params->_productList.size();
productIds.reserve(size);
productTypes.reserve(size);
for (auto product : params->_productList) {
productIds.push_back(product->_productId);
productTypes.push_back(product->_productType);
Expand All @@ -147,25 +152,45 @@ void BillingClient::queryProductDetailsAsync(QueryProductDetailsParams* params,
}

void BillingClient::launchBillingFlow(BillingFlowParams* params) {
if(!params) {
CC_LOG_WARNING("Params can't be null");
return;
}
GoogleBillingHelper::launchBillingFlow(_tag, params);
}

void BillingClient::consumeAsync(ConsumeParams* params, se::Object* listener) {
if(!params || !listener) {
CC_LOG_WARNING("Params or listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::consumeAsync(_tag, listenerId, params);
}

void BillingClient::acknowledgePurchase(AcknowledgePurchaseParams* params, se::Object* listener) {
if(!params || !listener) {
CC_LOG_WARNING("Params or listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::acknowledgePurchase(_tag, listenerId, params);
}

void BillingClient::queryPurchasesAsync(QueryPurchasesParams* params, se::Object* listener) {
if(!params || !listener) {
CC_LOG_WARNING("Params or listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::queryPurchasesAsync(_tag, listenerId, params->_productType);
}

void BillingClient::getBillingConfigAsync(GetBillingConfigParams* params, se::Object* listener) {
if(!params || !listener) {
CC_LOG_WARNING("Params or listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::getBillingConfigAsync(_tag, listenerId);
}
Expand All @@ -175,36 +200,67 @@ BillingResult* BillingClient::isFeatureSupported(const std::string& feature) {
}

void BillingClient::createAlternativeBillingOnlyReportingDetailsAsync(se::Object* listener) {
if(!listener) {
CC_LOG_WARNING("Listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::createAlternativeBillingOnlyReportingDetailsAsync(_tag, listenerId);
}

void BillingClient::isAlternativeBillingOnlyAvailableAsync(se::Object* listener) {
if(!listener) {
CC_LOG_WARNING("Listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::isAlternativeBillingOnlyAvailableAsync(_tag, listenerId);
}

void BillingClient::createExternalOfferReportingDetailsAsync(se::Object* listener) {
if(!listener) {
CC_LOG_WARNING("Listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::createExternalOfferReportingDetailsAsync(_tag, listenerId);
}

void BillingClient::isExternalOfferAvailableAsync(se::Object* listener) {
if(!listener) {
CC_LOG_WARNING("Listener can't be null");
return;
}
int listenerId = addListener(listener);
GoogleBillingHelper::isExternalOfferAvailableAsync(_tag, listenerId);
}

BillingResult* BillingClient::showAlternativeBillingOnlyInformationDialog(se::Object* listener) {
if(!listener) {
// Extending the return value of BillingResult.Normal behavior wouldn't get in here.
auto* builder = BillingResult::newBuilder();
return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build();
}
int listenerId = addListener(listener);
return GoogleBillingHelper::showAlternativeBillingOnlyInformationDialog(_tag, listenerId);
}

BillingResult* BillingClient::showExternalOfferInformationDialog(se::Object* listener) {
if(!listener) {
// Extending the return value of BillingResult.Normal behavior wouldn't get in here.
auto* builder = BillingResult::newBuilder();
return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build();
}
int listenerId = addListener(listener);
return GoogleBillingHelper::showExternalOfferInformationDialog(_tag, listenerId);
}

BillingResult* BillingClient::showInAppMessages(InAppMessageParams* params, se::Object* listener) {
if(!params || !listener) {
// Extending the return value of BillingResult.Normal behavior wouldn't get in here.
auto* builder = BillingResult::newBuilder();
return (*builder).setResponseCode(6).setDebugMessage("Listener can't be null").build();
}
int listenerId = addListener(listener);
return GoogleBillingHelper::showInAppMessages(_tag, listenerId, params->_inAppMessageCategoryIds);
}
Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/JniBilling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ jobject JniBilling::newProductDetailsParamsObject(int tag, const BillingFlowPara
return env->CallObjectMethod(builder, buildMethodId);
}

jobject JniBilling::newProductDetailsParamsListObject(int tag, std::vector<BillingFlowParams::ProductDetailsParams*> listParams) {
jobject JniBilling::newProductDetailsParamsListObject(int tag, const std::vector<BillingFlowParams::ProductDetailsParams*>& listParams) {
JNIEnv *env = cc::JniHelper::getEnv();
jclass listClass = env->FindClass("java/util/ArrayList");
jmethodID methodInit = env->GetMethodID(listClass, "<init>", "()V"); /* 无参构造 */
Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/JniBilling.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CC_DLL JniBilling {
private:
static jobject newSubscriptionUpdateParamsObject(const BillingFlowParams::SubscriptionUpdateParams* params);
static jobject newProductDetailsParamsObject(int tag, const BillingFlowParams::ProductDetailsParams* params);
static jobject newProductDetailsParamsListObject(int tag, std::vector<BillingFlowParams::ProductDetailsParams*> listParams);
static jobject newProductDetailsParamsListObject(int tag, const std::vector<BillingFlowParams::ProductDetailsParams*>& listParams);

static jobject newPurchaseUpdateListenerObject(int tag);
static jobject newUserChoiceBillingListenerObj(int tag);
Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/build-params/ConsumeParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ConsumeParams : public cc::RefCounted {
}

private:
ConsumeParams(const std::string&& purchaseToken) : _purchaseToken(purchaseToken) {
ConsumeParams(std::string&& purchaseToken) : _purchaseToken(purchaseToken) {
}

std::string _purchaseToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class InAppMessageParams : public cc::RefCounted {
}

private:
InAppMessageParams(const std::vector<int>&& inAppMessageCategoryIds):_inAppMessageCategoryIds(inAppMessageCategoryIds) {
InAppMessageParams(std::vector<int>&& inAppMessageCategoryIds):_inAppMessageCategoryIds(inAppMessageCategoryIds) {
}
friend class BillingClient;
std::vector<int> _inAppMessageCategoryIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class QueryProductDetailsParams : public cc::RefCounted {
}

private:
QueryProductDetailsParams(const std::vector<Product*>&& productLists) : _productList(productLists) {
QueryProductDetailsParams(std::vector<Product*>&& productLists) : _productList(productLists) {
}

private:
Expand Down

0 comments on commit b2d878f

Please sign in to comment.