Android Question Ultimate Help Needed: Can't remove AD_ID and keep Firebase working (All solutions failed)

softmicro

Member
Licensed User
Longtime User
Hello Erel and the B4X community,
I am in a very difficult situation with a B4A project and I have run out of ideas after trying every possible solution I could find. I would be very grateful for any help. **The Goal:** Update an existing app to target SDK 34 and submit it to Google Play. The app uses Firebase (Auth, Analytics, Messaging) but does not use ads, so I must declare "No" to the Advertising ID usage. **The Problem:**
The Firebase libraries automatically add the `com.google.android.gms.permission.AD_ID`. My attempts to remove it and keep Firebase functional have all failed. Here is a summary of everything I have tried:
1. **Simple Manifest Edit (`RemovePermission`):** I tried using `RemovePermission(com.google.android.gms.permission.AD_ID)`. The permission was still present in the final AAB. **Result: Failed.**
2. **Advanced Manifest Edit (`tools:node="remove"`):** I added the `tools` namespace and used `<uses-permission ... tools:node="remove" />`. The permission was *still* present in the final AAB. **Result: Failed.**
3. **`build.gradle` Exclusion:** I created a `build.gradle` file to exclude the `play-services-ads-identifier` module from all Google/Firebase dependencies. This successfully **removed the AD_ID permission** from the AAB. **Result: Success on permission, but...**
4. **App Crash:** After removing the permission with the `build.gradle` file, the app started crashing on launch with `java.lang.IllegalStateException: Default FirebaseApp is not initialized`. This happened because I had to comment out the `CreateResourceFromFile` macros for Firebase.
5. **Manual Initialization (Final Attempt):** To fix the crash, I tried to initialize Firebase manually. My project is a "classic" B4A project (not B4XPages), so I have a `Starter` service.
* I put the manual initialization code (`FirebaseApp.initializeApp(Context)`) at the very beginning of `Sub Service_Create` in the `Starter` service.
* The `Starter` service then calls `StartService(Firebasemessaging)`.
* However, the app **still crashes** with the exact same error (`Default FirebaseApp is not initialized`) when the `FirebaseMessaging` service tries to execute `fm.Initialize("fm")`. **Current Situation:** It seems the initialization in the `Starter` service is not being recognized by the `FirebaseMessaging` service when it starts. It's as if they are in different contexts or the order of execution is not what is expected. I am using B4A v13.30 (the IDE shows v13.40 is available). My `google-services.json` file is in the project's root folder.
I am completely stuck. How can I have a functional Firebase (especially Messaging and Auth) in my app while also successfully removing the `AD_ID` permission for Google Play? Is there a known issue or a different method I am missing? Thank you for your time.
 
Top