Firebase issues!

@dankly Yes I add a blank swift file with Firebase 10.2 :ok_hand:
Do you use firebase/admob.h or firebase/gma.h (Google Mobile Ads framework) ?

I used google mobile ads. I’m not at my computer atm but I’ll check what I’ve done and get back to you. In the meantime, can you post your firebase::gma::initialize function block?

Thanks !

Projucer :

Extra Compiler Flags :
-fno-aligned-allocation

Extra Linker Flags :
$(OTHER_LDFLAGS) -ObjC -lsqlite3 -lz

Custom Plist :

<plist version="1.0">
    <dict>
        <key>NSAppTransportSecurity</key>
            <dict>
                <key>NSAllowsArbitraryLoads</key>
                    <true/>
            </dict>
    </dict>
</plist>

Extra System Frameworks :
CoreMotion, MediaPlayer, AdSupport, MessageUI, CoreServices, CoreTelephony, JavaScriptCore, Security, StoreKit, SystemConfiguration, UIKit, Foundation, CoreMedia, MetalKit

Framework Search Paths :
/X/Firebase/Firebase10/FirebaseAnalytics
/X/Firebase/Firebase10/FirebaseCrashlytics
/X/Firebase/Firebase10/Google-Mobile-Ads-SDK
/X/firebase_cpp_sdk10/xcframeworks

Extra Custom Frameworks :
/X/Firebase/firebase_cpp_sdk10/xcframeworks/firebase.xcframework
/X/Firebase/firebase_cpp_sdk10/xcframeworks/firebase_analytics.xcframework
/X/Firebase/firebase_cpp_sdk10/xcframeworks/firebase_gma.xcframework
/X/Firebase/Firebase10/FirebaseCrashlytics/FirebaseCrashlytics.xcframework
/X/Firebase/Firebase10/FirebaseCrashlytics/GoogleDataTransport.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FBLPromises.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FirebaseAnalytics.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FirebaseAnalyticsSwift.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FirebaseCore.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FirebaseCoreInternal.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/FirebaseInstallations.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/GoogleAppMeasurement.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/GoogleAppMeasurementIdentitySupport.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/GoogleUtilities.xcframework
/X/Firebase/Firebase10/FirebaseAnalytics/nanopb.xcframework
/X/Firebase/Firebase10/Google-Mobile-Ads-SDK/GoogleMobileAds.xcframework
/X/Firebase/Firebase10/Google-Mobile-Ads-SDK/UserMessagingPlatform.xcframework

Header Search Paths & Extra Library Search Paths (Debug & Release):
/X/Firebase/Firebase10/FirebaseAnalytics
/X/Firebase/Firebase10/FirebaseCrashlytics
/X/Firebase/Firebase10/Google-Mobile-Ads-SDK
/X/Firebase/firebase_cpp_sdk10/xcframeworks
/usr/lib/swift

Custom Xcode Flags (Debug & Release):
FRAMEWORK_SEARCH_PATHS=“/X/Firebase/Firebase10/FirebaseAnalytics /X/Firebase/Firebase10/FirebaseCrashlytics
/X/Firebase/Firebase10/Google-Mobile-Ads-SDK /X/Firebase/firebase_cpp_sdk10/xcframeworks”, GCC_GENERATE_DEBUGGING_SYMBOLS=YES, STRIP_INSTALLED_PRODUCT=NO, COPY_PHASE_STRIP=NO

Xcode:

#include "firebase/analytics.h"
#include "firebase/analytics/event_names.h"
#include "firebase/analytics/parameter_names.h"
#include "firebase/analytics/user_property_names.h"
#include "firebase/app.h"
#include "firebase/future.h"
#include "firebase/gma.h"
#include "firebase/gma/ad_view.h"
#include "firebase/gma/interstitial_ad.h"
#include "firebase/gma/types.h"

using firebase::App;
using firebase::Future;
using firebase::gma::AdapterInitializationStatus;

    void initialise(const String& commandLine) override
    {
        printf("--- Initialisation Firebase\n");
        firebase::App* app = firebase::App::Create();
        printf("--- Created the firebase app %x\n",
                   static_cast<int>(reinterpret_cast<intptr_t>(app)));
        
        // Initialize the Google Mobile Ads library.
        printf("--- Initialisation GMA\n");
        firebase::InitResult result;
        Future<AdapterInitializationStatus> future = firebase::gma::Initialize(*app, &result);
        
        mainWindow.reset (new MainWindow (getApplicationName()));
        while (!ProcessEvents(1000)) {
            if (future.status() != firebase::kFutureStatusPending) {
                printf("\n\n==================YYYYYEEESSSSSS ==================\n\n\n");
                break;
            }
            else
                printf("WaitForFutureCompletion... kFutureStatusPending\n");
          }
     }

Do you drag & drop your “GoogleService-info.plist” into Xcode (under App Name) ?
Or add this file into your Producer, File Explorer, Source ?

I add the plist to Projucer, alongside the source folder rather than in it, although im not sure that matters.

Have you setup an account in admob? Im not talking about firebase.google.com I mean admob.google.com

1 Like

Yes, my admob account is okay:

  • I have my Application ID (ca-app-pub-758873…)
  • Approval status Ready
  • Interstitiel ID okay (ca-app-pub-75887316399…)
  • Payments ready

My GoogleService-Info.plist file:
(Download from Firebase.google.com after link admob with firebase. I just changed bool IS_ADS_ENABLED and IS_ANALYTICS_ENABLED to YES)
Is there anything else to do?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CLIENT_ID</key>
	<string>4882X07sls.apps.googleusercontent.com</string>
	<key>REVERSED_CLIENT_ID</key>
	<string>com.googleusercontent.apps.X</string>
	<key>API_KEY</key>
	<string>AIzaSyB4wAEIkpxleMX</string>
	<key>GCM_SENDER_ID</key>
	<string>488244303159</string>
	<key>PLIST_VERSION</key>
	<string>1</string>
	<key>BUNDLE_ID</key>
	<string>com.X</string>
	<key>PROJECT_ID</key>
	<string>X-firebase</string>
	<key>STORAGE_BUCKET</key>
	<string>X-firebase.appspot.com</string>
	<key>IS_ADS_ENABLED</key>
	<true></true>
	<key>IS_ANALYTICS_ENABLED</key>
	<true></true>
	<key>IS_APPINVITE_ENABLED</key>
	<true></true>
	<key>IS_GCM_ENABLED</key>
	<true></true>
	<key>IS_SIGNIN_ENABLED</key>
	<true></true>
	<key>GOOGLE_APP_ID</key>
	<string>1:488244303X</string>
	<key>ADMOB_APP_ID</key>
	<string>ca-app-pub-7588731X</string>
</dict>
</plist>

I added my app ID to the custom plist in projucer

GADApplicationIdentifier
ca-app-pub-7922487446890273~YOURID

See if that does anything for you

I’m trying to do this on my phone and it’s deleted the key and string but you understand what I mean don’t you?

I think this will add the ID to the info.plist in your project rather than it being in the google services one

Yes I add this GADApplicationIdentifier in Projucer Custom Plist but it doesn’t work better…
Like this :

<plist version="1.0">
    <dict>
        <key>NSAppTransportSecurity</key>
            <dict>
                <key>NSAllowsArbitraryLoads</key>
                    <true/>
            </dict>
        <key>GADApplicationIdentifier</key>
        <string>ca-app-pub-7588731639915518~X</string>
    </dict>
</plist>

Thanks

Right. Another observation, some of my includes are different to yours and I don’t have any ‘using’ at all.

Tomorrow when I get a chance I’ll upload a bare bones version of my main.cpp and maincomponent.h and maincomponent.cpp to see if you can edit and use it with your projucer file, just to get the demo adds working. If that works, it’s a problem in your source files, if not it should be a projucer issue.

1 Like

Yes!!! Perfect! Thanks !

This thread is great, and @dankly that would be really awesome. Thank you and everyone sharing their experiences here :slight_smile:

1 Like

Main.cpp

#include <JuceHeader.h>
#include “MainComponent.h”
#include “firebase/app.h”
#include “firebase/gma.h”

//==============================================================================
class AdsDemoApplication : public juce::JUCEApplication
{
public:
//==============================================================================
AdsDemoApplication() {}

const juce::String getApplicationName() override       { return ProjectInfo::projectName; }
const juce::String getApplicationVersion() override    { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override             { return true; }

//==============================================================================
void initialise (const juce::String& commandLine) override
{
    // Initialize the Google Mobile Ads library.
    
    firebase::InitResult result;
    firebase::Future<firebase::gma::AdapterInitializationStatus> future =
      firebase::gma::Initialize(&result);

    if (result != firebase::kInitResultSuccess) {
      // Initialization immediately failed, most likely due to a missing dependency.
      // Check the device logs for more information.
      return;
    }

    // Monitor the status of the future.
    // See "Use a Future to monitor the completion status of a method call" below.
    if (future.status() == firebase::kFutureStatusComplete &&
        future.error() == firebase::gma::kAdErrorCodeNone) {
      // Initialization completed.
    } else {
      // Initialization on-going, or an error has occurred.
    }
    
    mainWindow.reset (new MainWindow (getApplicationName()));
}

void shutdown() override
{
    mainWindow = nullptr; // (deletes our window)
}

//==============================================================================
void systemRequestedQuit() override
{
    quit();
}

void anotherInstanceStarted (const juce::String& commandLine) override {}

//==============================================================================

class MainWindow    : public juce::DocumentWindow
{
public:
    MainWindow (juce::String name)
        : DocumentWindow (name,
                          juce::Desktop::getInstance().getDefaultLookAndFeel()
                                                      .findColour (juce::ResizableWindow::backgroundColourId),
                          DocumentWindow::allButtons)
    {
        setUsingNativeTitleBar (true);
        setContentOwned (new MainComponent(), true);

       #if JUCE_IOS || JUCE_ANDROID
        setFullScreen (true);
       #else
        setResizable (true, true);
        centreWithSize (getWidth(), getHeight());
       #endif

        setVisible (true);
    }

    void closeButtonPressed() override
    {
        JUCEApplication::getInstance()->systemRequestedQuit();
    }

private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};

private:
std::unique_ptr mainWindow;
};

//==============================================================================

START_JUCE_APPLICATION (AdsDemoApplication)

MainComponent.h

#pragma once

#include <JuceHeader.h>
#include “firebase/future.h”
#include “firebase/gma/ad_view.h”
#include “firebase/gma/interstitial_ad.h”

//==============================================================================

class MainComponent : public juce::Component,
private juce::MultiTimer
{
public:
//==============================================================================
MainComponent();
~MainComponent() override;

//==============================================================================

void paint (juce::Graphics&) override;
void resized() override;
void timerCallback (int) override;

private:

// Banner ad requisites

std::unique_ptr<firebase::gma::AdView> adView;

juce::StringRef googleBannerID = "ca-app-pub-3940256099942544/2934735716"; // Demo

//==============================================================================

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)

};

MainComponent.cpp

#include “MainComponent.h”
#include “firebase/admob/types.h”

//==============================================================================
MainComponent::MainComponent()
{
auto area = juce::desktop::getInstance().getDisplays().getMainDisplay().userArea;
setSize(area.getWidth(), area.getHeight());

startTimer(1, 1000); // Banner Ad

setSize (620, 300);

}

MainComponent::~MainComponent()
{
if( adView.get() ) {adView->Destroy();}
}

void MainComponent::timerCallback(int timerID)
{
// Banner Ad Timer

if (timerID == 1)
{
    stopTimer(1);
    
    adView = std::make_unique<firebase::gma::AdView>();
    auto adSize = firebase::gma::AdSize::kBanner;
    
    adView->Initialize(static_cast<firebase::gma::AdParent>(getTopLevelComponent()->getWindowHandle()),
                           googleBannerID,
                       adSize);
    
    adView->SetPosition(firebase::gma::AdView::kPositionTop);
    
    firebase::gma::AdRequest ad_request;
    firebase::Future<firebase::gma::AdResult> load_ad_result = adView->LoadAd(ad_request);
    
    firebase::Future<void> result = adView->Show();
}

}

void MainComponent::paint (juce::Graphics& g) {g.fillAll(juce::Colours::black);}

void MainComponent::resized() {}

End Result

2 Likes