diff --git a/gma/integration_test/src/integration_test.cc b/gma/integration_test/src/integration_test.cc index 2a48d0066f..d44b0c869a 100644 --- a/gma/integration_test/src/integration_test.cc +++ b/gma/integration_test/src/integration_test.cc @@ -173,6 +173,12 @@ class FirebaseGmaUITest : public FirebaseGmaTest { void SetUp() override; }; +class FirebaseGmaMinimalTest : public FirebaseTest { + public: + FirebaseGmaMinimalTest(); + ~FirebaseGmaMinimalTest() override; +}; + // Runs GMA Tests on methods and functions that should be run // before GMA initializes. class FirebaseGmaPreInitializationTests : public FirebaseGmaTest { @@ -228,11 +234,11 @@ void FirebaseGmaTest::SetUpTestSuite() { } void FirebaseGmaTest::TearDownTestSuite() { - // Workaround: GMA does some of its initialization in the main - // thread, so if you terminate it too quickly after initialization - // it can cause issues. Add a small delay here in case most of the - // tests are skipped. - ProcessEvents(1000); + // GMA does some of its initialization in the main thread, so if you terminate + // it before initialization has completed, it can cause issues. So wait for + // any pending GMA initialization to be completed before calling terminate. + WaitForCompletion(firebase::gma::InitializeLastResult(), + "gma::InitializeLastResult"); LogDebug("Shutdown GMA."); firebase::gma::Terminate(); LogDebug("Shutdown Firebase App."); @@ -301,6 +307,10 @@ firebase::Variant FirebaseGmaTest::GetVariantMap() { return variant_map; } +FirebaseGmaMinimalTest::FirebaseGmaMinimalTest() {} + +FirebaseGmaMinimalTest::~FirebaseGmaMinimalTest() {} + FirebaseGmaUITest::FirebaseGmaUITest() {} FirebaseGmaUITest::~FirebaseGmaUITest() {} @@ -340,6 +350,26 @@ void FirebaseGmaPreInitializationTests::SetUpTestSuite() { // Test cases below. +TEST_F(FirebaseGmaMinimalTest, TestInitializeGmaWithoutFirebase) { + // Don't initialize mediation in this test so that a later test can still + // verify that mediation has not been initialized. + firebase::gma::DisableMediationInitialization(); + LogDebug("Initializing GMA without a Firebase App."); + firebase::InitResult result; +#if defined(ANDROID) + ::firebase::gma::Initialize(app_framework::GetJniEnv(), + app_framework::GetActivity(), &result); +#else // !defined(ANDROID) + ::firebase::gma::Initialize(&result); +#endif // defined(ANDROID) + EXPECT_EQ(result, ::firebase::kInitResultSuccess); + WaitForCompletion(firebase::gma::InitializeLastResult(), "gma::Initialize"); + LogDebug("Successfully initialized GMA."); + + LogDebug("Shutdown GMA."); + firebase::gma::Terminate(); +} + TEST_F(FirebaseGmaPreInitializationTests, TestDisableMediationInitialization) { // Note: This test should be disabled or put in an entirely different test // binrary if we ever wish to test mediation in this application. diff --git a/gma/src/android/gma_android.cc b/gma/src/android/gma_android.cc index a1459e20b8..bcc7e35949 100644 --- a/gma/src/android/gma_android.cc +++ b/gma/src/android/gma_android.cc @@ -285,11 +285,7 @@ Future Initialize(JNIEnv* env, jobject activity, env->GetJavaVM(&g_java_vm); } - // GMA requires Google Play services if the class - // "com.google.android.gms.ads.internal.ClientApi" does not exist. - if (!util::FindClass(env, "com/google/android/gms/ads/internal/ClientApi") && - google_play_services::CheckAvailability(env, activity) != - google_play_services::kAvailabilityAvailable) { + if (!util::Initialize(env, activity)) { if (init_result_out) { *init_result_out = kInitResultFailedMissingDependency; } @@ -298,7 +294,12 @@ Future Initialize(JNIEnv* env, jobject activity, return Future(); } - if (!util::Initialize(env, activity)) { + // GMA requires Google Play services if the class + // "com.google.android.gms.ads.internal.ClientApi" does not exist. + if (!util::FindClass(env, "com/google/android/gms/ads/internal/ClientApi") && + google_play_services::CheckAvailability(env, activity) != + google_play_services::kAvailabilityAvailable) { + util::Terminate(env); if (init_result_out) { *init_result_out = kInitResultFailedMissingDependency; } diff --git a/release_build_files/readme.md b/release_build_files/readme.md index e1ff9696b8..24f7ac2017 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -627,6 +627,10 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### Upcoming Release +- Changes + - GMA (Android): Fixed a crash when initializing GMA without a Firebase App. + ### 11.3.0 - Changes - General (Android): Update to Firebase Android BoM version 32.2.0.