我用 cocos2dx 4.0, 第一次可以跑通,睡了一觉再启动就不行了
AppDelegate.h
#include “cocos2d.h”
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include “firebase/app.h”
#include “firebase/Analytics.h”
#include “firebase/admob.h”
#include “firebase/admob/banner_view.h”
#include “firebase/admob/rewarded_video.h”
#include “firebase/admob/interstitial_ad.h”
#include <jni.h>
#include “platform/android/jni/JniHelper.h”
#endif
class AppDelegate : private cocos2d::Application
{
//my addition
private:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
std::unique_ptr<::firebase::App> _pFirebaseApp;
#endif
};
AppDelegate.cpp
bool AppDelegate::applicationDidFinishLaunching() {
//my addition
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
_pFirebaseApp = std::unique_ptr<::firebase::App>(::firebase::App::Create(JniHelper::getEnv(), JniHelper::getActivity()));
const char* kAdMobAppID = “ca-app-pub-3940256099942544~3347511713”;
firebase::admob::Initialize(*_pFirebaseApp, kAdMobAppID);//每个应用不同"ca-app-pub-7333122515883217~7113534659"
#endif
}
HelloWorldScene.cpp
bool HelloWorld::init(){
//my addition
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
firebase::admob::AdRequest my_ad_request = {};
namespace admob = ::firebase::admob;
admob::InterstitialAd* interstitial = new admob::InterstitialAd();
interstitial->Initialize(cocos2d::JniHelper::getActivity(), “ca-app-pub-3940256099942544/8691691433”);
#endif
std::string menuItemStr;
menuItemStr = “load_interstitialAd”;
_load_interstitialAd = MenuItemFont::create(menuItemStr.c_str(),
[&](cocos2d::Ref *pSender) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
if (interstitial->InitializeLastResult().status() ==
::firebase::kFutureStatusComplete &&
interstitial->InitializeLastResult().error() ==
firebase::admob::kAdMobErrorNone) {
interstitial->LoadAd(my_ad_request);
}
#endif
});
menuItemStr = “show_interstitialAd”;
_show_interstitialAd = MenuItemFont::create(menuItemStr.c_str(),
[&](cocos2d::Ref *pSender) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
if (interstitial->LoadAdLastResult().status() ==
::firebase::kFutureStatusComplete &&
interstitial->LoadAdLastResult().error() ==
firebase::admob::kAdMobErrorNone) {
interstitial->Show();
}
#endif
});
Menu* menuBook = Menu::create(_load_interstitialAd, _show_interstitialAd, NULL);
menuBook->setPosition(Vec2(240, 88));
menuBook->alignItemsVertically();
addChild(menuBook, 3);
}
and when I click “_load_interstitialAd”, it’s break. I am so confused : ( ,someone please help me
PS:我一按load按钮就挂了,下面是按下时候的日志
2021-01-07 21:16:52.324 8614-8614/gklutz.USEFirebase.panda619 I/hwaps: JNI_OnLoad
2021-01-07 21:16:52.553 8614-8657/gklutz.USEFirebase.panda619 W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
2021-01-07 21:16:52.553 8614-8657/gklutz.USEFirebase.panda619 W/google-breakpad: Chrome build fingerprint:
2021-01-07 21:16:52.553 8614-8657/gklutz.USEFirebase.panda619 W/google-breakpad: 70.0.3538.110
2021-01-07 21:16:52.553 8614-8657/gklutz.USEFirebase.panda619 W/google-breakpad: 353811050
2021-01-07 21:16:52.553 8614-8657/gklutz.USEFirebase.panda619 W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
2021-01-07 21:16:52.555 8614-8657/gklutz.USEFirebase.panda619 A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 8657 (GLThread 4887)