Android Question package com.google.android.gms.ads.identifier does not exist

hatzisn

Expert
Licensed User
Longtime User
Good morning, everyone. I try to compile a code that gets the AdvertisingID with the code that follows and I get this error:

B4A Version: 10.2
Java Version: 11
Parsing code. (0.17s)
Building folders structure. (0.07s)
Running custom action. (0.06s)
Running custom action. (0.06s)
Compiling code. (0.20s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.01s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. (0.00s)
Compiling generated Java code. Error
src\b4a\example\main.java:4: error: package com.google.android.gms.ads.identifier does not exist
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

javac 11.0.1


Block with Error:
#if b4a
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[]>() {
                   [USER=69643]@override[/USER]
                   public Object[] call() throws Exception {
                       String id = AdvertisingIdClient.getAdvertisingIdInfo(mostCurrent).getId();
                       return new Object[] {true, id};
                   }
               }); }
#End If
#End If

Meanwhile following is the SDK Manager with the libraries installed. What can be wrong (the same code runs flawlessly in another application)?
This is the Manifest:

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.

'************ Google Play Services Base ************
AddApplicationText(
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************


'Edit for Android 9
'***********************************************************
AddApplicationText(
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
)
'***********************************************************

'To Connect to non https sites
CreateResourceFromFile(Macro, Core.NetworkClearText)


'For google play billing
CreateResourceFromFile(Macro, GooglePlayBilling.GooglePlayBilling)


'To get advertising ID
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)


'=============================================================
'Fused Location Provider
'*************************************************************
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddApplicationText(<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />)
'*************************************************************

'Light theme
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values-v20, theme.xml,
<resources>
<style
name="LightTheme" parent="@android:style/Theme.Material.Light">
</style>
</resources>
)
CreateResource(values-v14, theme.xml,
<resources>
<style
name="LightTheme" parent="@android:style/Theme.Holo.Light">
</style>
</resources>
)

And there is also this code in the app:

'Fused Location Provider - Through NHFusedLocation
'=============================================================
'*************************************************************
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location
'*************************************************************

Edit: The app that runs flawlessly is not a B4XPages application and the application where the error occurs is B4X Pages app.

1609242537484.png
 

hatzisn

Expert
Licensed User
Longtime User
It is fixed with the tutorial. I had not added the FirebaseAdMob.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Hi Erel, the resource is not available anymore...
I got the same error
com.google.android.gms.ads.identifier does not exist

Have you added the FirebaseAdMob?
 
Upvote 0
Top