Android Question FirebaseAdMob2 Ad ID hangs on Android 7 in B4A 13.40

I am experiencing a problem in B4A 13.40 when using the FirebaseAdMob2 library in a Non-B4XPages project (in the Activity). On Android 7 and lower, the application does not receive the Advertising ID (Ad ID) and remains stuck at the Ad ID retrieval step.


Code Reference:
B4X Forum thread on Advertising ID

Paths Configuration:
  • JDK: 19.0.2
  • android.jar: 36

Additional Information:
  • In B4A 12.80 with JDK 19.0.2 and android.jar 33, the Ad ID was successfully retrieved on Android 7; no issues occurred.
  • In B4A 13.40 with the same JDK 19.0.2 and android.jar 33, the application still gets stuck at the Ad ID retrieval step on Android 7.

Testing Note:
  • The target android.jar 36 is intended for testing because I want to use the following manifest code:

B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values, theme.xml,
<resources>
    <style
        name="LightTheme" parent="@android:style/Theme.Material.Light">
       <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>
)

It seems that changes in B4A 13.40 affect the behavior of FirebaseAdMob2 on older Android versions, preventing Ad ID retrieval and blocking the application.
 
Looks like a chatgpt question. Please post the relevant code and logs.

You're right, the first post was written with ChatGPT. I was trying to get help from it, but as usual the answers were wrong. It told me that if I post the question in that way here, I might get a proper solution.


Anyway, here’s the actual setup I’m using:
Added the FirebaseAdMob2 library.
Added these two lines to the manifest.
B4X:
AddPermission(com.google.android.gms.permission.AD_ID)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

And here’s my full code:
B4X:
Sub Process_Globals
    Dim uniqueID As String
End Sub
Sub Globals
    Private tm As Timer
    Private bg As ImageView
End Sub

Private Sub GetAdvertisingId As ResumableSub
    Dim jo As JavaObject = Me
    jo.RunMethod("GetAdvertisingId", Null)
    Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
    Return Id
End Sub
#if Java
import java.util.concurrent.Callable;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;

public static void GetAdvertisingId() {
   BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
       , new Callable<Object[]>() {
                   @Override
                   public Object[] call() throws Exception {
                       String id = AdvertisingIdClient.getAdvertisingIdInfo(mostCurrent).getId();
                       return new Object[] {true, id};
                   }
               }); }
#End If


Sub Activity_Create(FirstTime As Boolean)
    bg.Initialize("")
    bg.Gravity=119
    bg.Bitmap=LoadBitmapSample(File.DirInternal, "demo.jpg", 100%x, 100%y)
    Activity.AddView(bg, 0, 0, 100%x, 100%y)

    tm.Initialize("tm",2000)
    tm.Enabled=True
End Sub
Sub tm_Tick
    tm.Enabled=False

    Log("Getting Advertising ID...")
    Wait For (GetAdvertisingId) Complete (Id As String)
    If Id <> "" Then uniqueID=Id
    Log("Advertising ID received: " & Id)
   
    StartActivity(login)
    Activity.Finish
End Sub

And this is the log I see (waited 5 minutes, nothing happens, the app just stays stuck at this point):
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
Getting Advertising ID...
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
And check this information in the FirebaseAdmob2 lib (Android 8+):

 
Upvote 0
And check this information in the FirebaseAdmob2 lib (Android 8+):

Thank you for your response.
Due to my users, I have to use minSdkVersion=14.
It seems the issue is related to B4A 13.40.


As I mentioned in my first message, even during my own testing:
In B4A 12.80 with JDK 19.0.2 and android.jar 33, the Ad ID was successfully retrieved on Android 7 without any issues.
In B4A 13.40 with the same JDK 19.0.2 and android.jar 33, the application still gets stuck at the Ad ID retrieval step on Android 7.

So, under the exact same configuration, there’s no issue in B4A 12.80, but the problem exists in B4A 13.40.
 
Upvote 0
The app cannot be stuck because of this code.

B4A v13.4 is expected to run with an updated SDK. Follow the installation instructions.

I've updated the ads identifier example: https://www.b4x.com/android/forum/threads/advertising-id.101050/#content
Thanks for the update on the identifier example.

But I just downloaded the example from this link: https://www.b4x.com/android/forum/threads/advertising-id.101050/#content and tested it on a phone running Android 7. Again, it stops when trying to get the AdvertisingId. Funny thing is, it doesn’t even throw an error!

For installing B4A 13.4, I just followed the installation instructions exactly.
 
Last edited:
Upvote 0
Google SDK is compatible with Android 8+. minSdkVersion should be 26 (Android 8).
If I set minSdkVersion to 26, I’ll lose around 20% of my users.

Ever since I downloaded the required tools from this link: https://www.b4x.com/b4a.html and put C:\android\platforms\android-36\android.jar in the paths configuration for B4A 12.8, I’ve been getting this compile error:

B4X:
Maven artifact not found: com.google.guava/guava
Source: FirebaseAdMob2

Even when I switch to C:\android\platforms\android-33\android.jar, I still get the same error.

I also tried putting com.google.guava-listenablefuture.jar inside both the internal and additional libraries folders, but that didn’t help either.

If I can fix this issue in B4A 12.8 so it compiles correctly, there’s a 90% chance that the AD_ID problem on Android-36 will be solved — because basically I’m only facing this issue in B4A 13.40
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't control Google SDK requirements. If B4A v12.8 with an old SDK works for you then go ahead. Make sure to test it with targetSdkVersion 35 and on an Android 15+ device.

Note that Google SDK isn't the same as the Android jar version. Google SDK = Google Play Services.
 
Upvote 0
I don't control Google SDK requirements. If B4A v12.8 with an old SDK works for you then go ahead. Make sure to test it with targetSdkVersion 35 and on an Android 15+ device.

Note that Google SDK isn't the same as the Android jar version. Google SDK = Google Play Services.
I fixed the compile issue in B4A 12.80.
With the output from this version, the AD_ID problem on older Android versions is gone.
It works fine on both Android 7 and Android 15.
Seems like the older B4A output actually supports more phones than the newer one.
 
Upvote 0
Top