Android Question Problem with AdView

Massy

Member
Licensed User
Longtime User
Hi all, I'm trying to implement AdMob in my apps, I followed all the instructions in this post: http://www.b4x.com/android/forum/threads/admob-tutorial-add-ads-to-your-application.7300/
but when I add the line: "Dim AdView1 As AdView" I always get this error: Unknown type AdView...
I added the google-play-services.jar file in the Libraries folder and also the GoogleMaps library but still I get that error...
I read a lot of posts about this problem in the forum but couldn't find anything of any help....
Anyone as any idea of what could I be doing wrong?
Thanks a lot for your help
Massy
 

Douglas Farias

Expert
Licensed User
Longtime User
use my code
and pay atention on this
Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER ) <<<<<<<< here


Adbox.SIZE_SMART_BANNER this is important lol


use this
B4X:
Sub Globals
  Private Adbox As AdView
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER )
    Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    If 100%x > 100%y Then height = 32dip Else height = 50dip
    Else
    height = 90dip
    End If
    Activity.AddView(Adbox, 0dip, 100%y - height, 100%x, height)
      Adbox.LoadAd
 
Upvote 0

Massy

Member
Licensed User
Longtime User
use my code
and pay atention on this
Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER ) <<<<<<<< here

Nothing... if this can help you I noticed that I begin getting the error just declaring the Dim..
If I only have the "#AdditionalRes: D:\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms" the app run ok, but if I just add "Dim AdView1 As AdView" in sub globals the app crash and give error... and in the device it appears a message saying the application has stopped abnormally
 
Upvote 0

Massy

Member
Licensed User
Longtime User
Can you post the error from the logs?

Are you using B4A v3.82?
Hi Erel, I was using an old version of b4a, now I've updated to 3.82 and it keeps giving me the error but it is changed... this is the log:

LogCat connected to: 07b2c4f2
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


PackageAdded: package:com.my.app


** Activity (main) Create, isFirst = true **


java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 4452000. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.x(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.internal.ai.a(Unknown Source)
at com.google.android.gms.internal.av.aH(Unknown Source)
at com.google.android.gms.internal.av.a(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at anywheresoftware.b4a.admobwrapper.AdViewWrapper.LoadAd(AdViewWrapper.java:118)
at com.my.app.main._activity_create(main.java:405)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.my.app.main.afterFirstLayout(main.java:98)
at com.my.app.main.access$100(main.java:16)
at com.my.app.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 4452000. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
PackageAdded: package:com.my.app
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
PackageAdded: package:com.my.app
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
PackageAdded: package:com.my.app
** Activity (main) Create, isFirst = true **
java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 4452000. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />


at com.google.android.gms.common.GooglePlayServicesUtil.x(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.internal.ai.a(Unknown Source)
at com.google.android.gms.internal.av.aH(Unknown Source)
at com.google.android.gms.internal.av.a(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at anywheresoftware.b4a.admobwrapper.AdViewWrapper.LoadAd(AdViewWrapper.java:118)
at com.my.app.main._activity_create(main.java:405)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)


at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.my.app.main.afterFirstLayout(main.java:98)
at com.my.app.main.access$100(main.java:16)
at com.my.app.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
 
Last edited:
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
you is using the lib i sended you yesterday?

#AdditionalRes:

copy this lib #AdditionalRes: <<<< to your b4a need is the same
i sended to u a version 17 i think


u need have #AdditionalRes: <
and the same lib on your b4a lib folder

on the manifest

B4X:
'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)
'End of AdMob

anjd this code to load
B4X:
Sub Globals
  Private Adbox As AdView
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER )
    Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    If 100%x > 100%y Then height = 32dip Else height = 50dip
    Else
    height = 90dip
    End If
    Activity.AddView(Adbox, 0dip, 100%y - height, 100%x, height)
      Adbox.LoadAd
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Expected 5077000 but found 4452000.

in the #AdditionalRes: is one version v9 for example

int the b4a/libraries/googleplaservices.jar is v18

need is the same, your code is correct now i think only the diferent versions of libs
 
Upvote 0

seby8181

Member
Licensed User
Longtime User
Hi,
i did all the tutorial steps, but when i try to compile my program i found this error:
ERROR: resource directory 'C:\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res -A ..\Files -F bin\temp.ap_' does not exist

what means?
note:
sdk versione: 23

i post my screenshot:



thanks a lot!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…