firebase / firebase-cpp-sdk

Firebase C++ SDK
http://firebase.google.com
Apache License 2.0
278 stars 114 forks source link

[Bug] Firebase C++ Admob SDK is not compatible to Android Admob SDK 20 (and cause crashes!) #621

Closed solodon4 closed 2 years ago

solodon4 commented 3 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

When I try to initialize AdMob on Android with either

    ::firebase::InitResult am_res = ::firebase::admob::Initialize(*app, kAdMobAppID);

or

::firebase::InitResult am_res = ::firebase::admob::Initialize(cocos2d::JniHelper::getEnv(), cocos2d::JniHelper::getActivity(), kAdMobAppID);

I get the following error and assertion at run-time:

 W/System.err: java.lang.NoSuchMethodError: no static method "Lcom/google/android/gms/ads/MobileAds;.initialize(Landroid/content/Context;Ljava/lang/String;)V"
 W/System.err:     at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
 W/System.err:     at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:74)
 W/System.err:     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1521)
 W/System.err:     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
 E/firebase: method_ids[i] || (method.optional == kMethodOptional)
 A/firebase: Unable to find Method com/google/android/gms/ads/MobileAds.initialize (signature '(Landroid/content/Context;Ljava/lang/String;)V', static).  Please verify the AAR which contains the com/google/android/gms/ads/MobileAds class is included in your app.

which happens on an actual Android device (Lollipop, API 23) and an emulator (Pixel 4, API 24).

When I run APK analyzer it only shows 2 relevant initialize methods and none of them takes String as second argument:

M d 1   1   72  com.google.android.gms.ads.MobileAds void initialize(android.content.Context)
M d 1   1   74  com.google.android.gms.ads.MobileAds void initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener)

Based on the call stack I see, my guess is that this is related to these lines in Firebase AdMob code but I can't tell whether it is indeed still a requirement.

Here is the relevant part of the call stack:

<unknown> 0x00000000b02f3424
raise 0x00000000af75f82b
abort 0x00000000af756e07
firebase::DefaultLogCallback(firebase::LogLevel, char const*, void*) 0x000000008bd8eb8a
firebase::LogMessageWithCallbackV(firebase::LogLevel, char const*, char*) 0x000000008bd8ec47
firebase::LogAssert(char const*, ...) 0x000000008bd8ee89
firebase::util::LookupMethodIds(_JNIEnv*, _jclass*, firebase::util::MethodNameSignature const*, unsigned int, _jmethodID**, char const*) 0x000000008bd8f7d6
firebase::admob::mobile_ads::CacheMethodIds(_JNIEnv*, _jobject*) 0x000000008bd6943b
firebase::admob::Initialize(_JNIEnv*, _jobject*, char const*) 0x000000008bd693eb
firebase::admob::Initialize(firebase::App const&, char const*) 0x000000008bd69210

This is possibly a regression as I had AdMob properly working with earlier version of Firebase C++ SDK (6.* something). Here are other dependencies I'm using:

    // Google Play Services
    implementation 'com.google.android.gms:play-services-auth:19.2.0'
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.android.gms:play-services-games:20.0.0'
    implementation 'com.google.android.gms:play-services-nearby:18.0.0'

    // Chartboost: https://answers.chartboost.com/en-us/child_article/android-integration
    implementation 'com.chartboost:chartboost-sdk:8.2.1'

    // AdMob Mediation
    implementation 'com.google.ads.mediation:adcolony:4.5.0.0'
    implementation 'com.google.ads.mediation:chartboost:8.2.1.0'

    // Mediation Test Suite
    implementation 'com.google.android.ads:mediation-test-suite:2.0.0'

    // Firebase
    implementation 'com.google.firebase:firebase-analytics:19.0.0'
    implementation 'com.google.firebase:firebase-ads:19.8.0'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-dynamic-links:20.1.1'
    implementation 'com.google.firebase:firebase-config:21.0.0'
    implementation 'com.google.firebase:firebase-crashlytics-ndk:18.2.0'
    implementation 'com.google.firebase:firebase-perf:20.0.2'
    implementation 'com.google.firebase:firebase-storage:20.0.0'

What am I possibly doing wrong or is there a workaround if it is indeed a bug on your side?

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase C++ quickstarts ? What's the issue repro rate? (eg 100%, 1/5 etc)

No, you guys don't keep your samples up to date to be built with recent build tools, side-by-side NDK etc. plus they require too much setup.

google-oss-bot commented 3 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

solodon4 commented 3 years ago

P.S. This is probably related to the fact that MobileAds.initialize(Context, String) is deprecated

chkuang-g commented 3 years ago

@solodon4 Thank you for pointing it out!

It does seems like MobileAds.initialize(Context, String) is removed, and C++ SDK is still using it here. https://github.com/firebase/firebase-cpp-sdk/blob/0c8c8b29bc2d62d66c6ac49ff2c3fb04f815a687/admob/src/android/admob_android.cc#L47

That is, ::firebase::admob::Initialize(app, app_id) is probably no longer safe to use.

Let me consult with the team and see what is the alternatives moving forward.

Shawn

chkuang-g commented 3 years ago

AFAIK, firebase-ads uses Admob 19, and MobileAds.initialize(Context, String) is removed in 20.

We actually have integration test for this as well. https://github.com/firebase/firebase-cpp-sdk/blob/3c2190901976a218cd4dc91b0e6aae5afc8d9291/admob/integration_test/src/integration_test.cc#L114

My guess is some of your dependencies may requires admob 20 and Gradle ended up bumping up the version. (Those com.google.ads.mediation looks pretty suspicious :/)

I'll report this to the team and see what we can do.

Shawn

solodon4 commented 3 years ago

Thank you @chkuang-g! I did try your hypothesis over the weekend and indeed if I downgrade all 3 of the mediation packages to the last version that depended on admob 19:

    // AdMob Mediation
    implementation 'com.google.ads.mediation:adcolony:4.4.1.0'
    implementation 'com.google.ads.mediation:chartboost:8.2.0.0'

    // Mediation Test Suite
    implementation 'com.google.android.ads:mediation-test-suite:1.5.0'

the initialization goes through successfully. Apparently all 3 require admob 20 SDK in their latest versions.

chkuang-g commented 3 years ago

Currently Firebase Admob C++ SDK only support Android Admob 19 SDK, since Admob 20 SDK introduced a lot of breaking changes, as you can see now.

Is downgrading the mediation packages an appropriate workaround for you? If not, please let us know your scenario and we can forward the information to the team.

Shawn

solodon4 commented 3 years ago

Thanks @chkuang-g! Downgrading mediation packages versions certainly unblocks me for now as I can work on other parts of the code, however, I'd need an actual solution to this problem eventually as I can see via mediation test suite warnings about SDK versions of providers as well as an error with one of them. I can live with those for now, but please don't close this bug until you guys fix the underlying issue so that I can track it on my side. Thank you!

frozax commented 2 years ago

Where can we see the current version compatibility between the Firebase C++ sdk and the associated SDKs (especially Google Ads). I don't know where to look for this information, and therefore don't know if it's safe for me to finally move to Google Ads 20 as I'm using firebase_cpp_sdk.

jonsimantov commented 2 years ago

We refreshed and updated the GMA C++ SDK in the Firebase C++ SDK 9.2.0 release. The old firebase::admob namespace is now deprecated; the new version, in firebase::gma, has been completely rewritten and now supports the latest AdMob iOS and Android versions.