Forums

OverviewV-Play 1 Support › AdMob plugin usage

Tagged: ,

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #5766

    Raimonds

    Hi,

    I’m trying to get AdMob plugin to work but without success

    I added AdMob tag to “Empty V-Play” project

    When i run it, there are errors with AdMob enum

    C:/Projects/_VPlay/BannerExample-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/qml/main.qml:65: ReferenceError: Can’t find variable: AdMob

     

    import VPlay 1.0
    import QtQuick 1.1
    import VPlay.plugins.admob 1.0
    GameWindow {
        activeScene: scene
    
        width: 960
        height: 640
        <SOME CONTENT> 
            AdMob {
                id: admobSmart;
                publisherId: "pub-22320XXXXXXXXX"
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                banner:AdMob.Smart
                testDeviceId: "Test12345678";
            }
        }
    }
    
    

     

    Can anyone can tell me what is wrong?

    Best Regards
    Raimonds

    #5767

    Christian
    V-Play Team

    Hi Raimonds,

    the problem is, that on platforms where admob is not supported (i.e. all platforms except iOS and Android), the enum cannot be resolved. You can do the following to resolve this issue when you test your game on the desktop:

    a.) Add a conditional binding to use the AdMob enum, i.e. use this:

    banner: system.desktopPlatform ? 0 : AdMob.Smart

     

    b.) Only load the AdMob item on platforms where it is supported with a Loader. Like in the following example:

    Loader {
      sourceComponent: system.desktopPlatform ? undefined : admobComponent
    }
    
    Component {
      id: admobComponent
      AdMob {
        // your admob code goes here
        banner: AdMob.Smart
      }
    }

     

    EDIT: Option (b) does not work with AdMob Smart banners, except the Loader is anchored to the top left corner of the gameWindowAnchorItem. In every other case, the AdMob item will be created slightly off screen by the loader and then repositioned. Between creating and repositioning, the Ad tries to show up, and since it’s not fully on screen, the AdMob SDK blocks all Ads. However, this problem only appears when the Component you load is only an AdMob item. Using the Loader item to load Scenes with AdMob items in it is no problem!

    Cheers, Chris

    #5768

    Raimonds

    Thanks Chris for quick answer!

    Additional confusion

    I’m following http://v-play.net/doc/plugins1-admob.html

    testDeviceId : QString

    Provide your device’s id here to receive test ads.

    What kind of ID and where i can find it?

     

    Additional… <V-PlaySDK>\Examples\V-PlaySDK\plugins\AdmobTest\qml\config.json

    in config is line for “plugins”

    “plugins”:[“admob”]

    Do i need it? In http://v-play.net/doc/plugins1-admob.html has nothing mentioned about it…

     

    #5769

    Christian
    V-Play Team

    You’re welcome Raimonds!

    You get the testDeviceId by inspecting the log output on your Android device. Here is a detailed explanation for it: http://stackoverflow.com/questions/4524752/how-can-i-get-device-id-for-admob

    Thanks for bringing up this question – we will enhance the documentation so it will be more clear for future customers.

    You are right, the hint about adding it to the config file is also missing in the docs – please make sure to add it to the config file, we’ll also add this information to the next doc version. Well spotted 😉

    Cheers, Chris

    #5770

    Raimonds

    Christian said:

    Here is a detailed explanation for it: http://stackoverflow.com/questions/4524752/how-can-i-get-device-id-for-admob

    From This link there is no clarity how to get Device ID if i only use Qt V-Play… i have no other tools installed.

     

    I found that there is an app which shows DeviceID

    https://play.google.com/store/apps/details?id=com.redphx.deviceid

    but from

    http://stackoverflow.com/questions/4524752/how-can-i-get-device-id-for-admob

    i don’t understand… Do i have to hash it or not?

     

    #5771

    Christian
    V-Play Team

    The second answer on stackoverflow indeed is a bit confusing – you do not need to hash the deviceId, as the AdMob SDK does this for you. However, using the app you mentioned for getting the deviceId is a great solution for finding out the deviceId, we’ll add that to the docs!

    Cheers, Chris

    #5823

    Raimonds

    Hi Chris,

    I have tried to test my test app with AdMob, but with no success :(

    I took empty V-Play project…

    I tested on my Samsung Galaxy Pocet, but app is running as there was no additional components (AdMob Component is not visible)

     

    Config

    {
      "title": "BannerTest",
      "identifier": "net.vplay.builds.BannerTest",
      "orientation": "landscape",
      "versioncode": 1,
      "versionname": "1.0",
      "plugins":["admob"]
    }
    

     

     

    Source

    import VPlay 1.0
    import QtQuick 1.1
    import VPlay.plugins.admob 1.0
    GameWindow {
        activeScene: scene
        // the size of the Window can be changed at runtime by pressing the number keys 1-7
        // the content of the logical scene size (480x320 by default) gets scaled to the window size based on the scaleMode
        // you can set this size to any resolution you would like your project to start with, most of the times the one of your main target device
        // this resolution is for iPhone 4 & iPhone 4S
        // change this to a portrait resolution (e.g. 640x960) for games in portrait mode
        width: 960
        height: 640
        
        Scene {
            id: scene
            // the "logical size" - the scene content is auto-scaled to match the GameWindow size
            // change this to 320x480 for games in portrait mode
            width: 480
            height: 320
            
            // background rectangle matching the logical scene size (= safe zone available on all devices)
            Rectangle {
                id: rectangle
                anchors.fill: parent
                color: "grey"
                
                Text {
                    id: textElement
                    // qsTr() uses the internationalization feature for multi-language support
                    text: qsTr("Hello World")
                    color: "#ffffff"
                    anchors.centerIn: parent
                }
                
                // use a MultiTouchArea instead of a MouseArea to detect multiple simultaneous touches
                MouseArea {
                    anchors.fill: parent
                    
                    // when the rectangle that fits the whole scene is pressed, change the background color and the text
                    onPressed: {
                        textElement.text = qsTr("Scene-Rectangle is pressed at position " + mouseX + "," + mouseY);
                        rectangle.color = "black";
                        console.debug("pressed position:", mouseX, mouseY);
                    }
                    
                    onPositionChanged: {
                        textElement.text = qsTr("Scene-Rectangle is moved at position " + mouseX + "," + mouseY);
                        console.debug("mouseMoved or touchDragged position:", mouseX, mouseY);
                    }
                    
                    // revert the text & color after the touch/mouse button was released
                    // also States could be used for that - search for "QML States" in the doc
                    onReleased: {
                        textElement.text = qsTr("Hello World");
                        rectangle.color = "grey";
                        console.debug("released position:", mouseX, mouseY);
                    }
                }
            }
            Loader {
              sourceComponent: system.desktopPlatform ? adMobDesktopC : admobComponent
              anchors.bottom: scene.bottom
              anchors.horizontalCenter: scene.horizontalCenter
            }
    
            Component {
              id: admobComponent
              AdMob {
                publisherId: "pub-2232083613XXXXXX"
                testDeviceId: "374092A335XXXXXX"
                // your admob code goes here
                banner: AdMob.Smart
              }
            }
            Component
            {
            id:adMobDesktopC
            Rectangle
            {
                id:rect
                color: "Red"
                height: 50
                width: 380
            }
    
            }
        }
    }
    
    

     

     

     

    #5828

    Christian
    V-Play Team

    Did you try to have a look at the log output? Is it saying anything “suspicious”?

    Cheers, Chris

    #5829

    Raimonds

    How can i debug my app? I build my testApp with build server and install it on device. How can i get some output on device?

    Raimonds

    #5830

    Christian
    V-Play Team

    You can follow the steps from Android Developers documentation about on-device debugging and then inspect the LogCat output.

    Cheers, Chris

    #5846

    Alex
    V-Play Team

    Hi Raimonds,

    the problem you are facing only occurs when using the AdMob component within a Loader component.

    Somehow the Admob component is not able to resize itself properly when added with the Loader, causing the Ad to lack space to be displayed.

    Until i track down the exact issue you can use the AdMob component without the Loader like this (and ignore the error message on desktop platform):

        AdMob {
          publisherId: "pub-2232083613XXXXXX"
          testDeviceId: "374092A335XXXXXX"
          banner: AdMob.Smart
          anchors.bottom: scene.bottom
          anchors.horizontalCenter: scene.horizontalCenter
        }

    Cheers,
    Alex

    #5847

    Raimonds

    Hi Alex,

    I tested without Loader and still no luck… :(

    Am I the only one facing this problem?

     

    And I didn’t get output from device…

    #5848

    Alex
    V-Play Team

    Can you test the following Code, only replace the publisherId and the testDeviceId with yours:

    GameWindow {
      width: 960
      height: 640
    
      Scene {
        id: scene
        width: 480
        height: 320
        AdMob {
          publisherId: "XXX" // replace with yours
          testDeviceId: "XXX" // replace with yours
          banner: AdMob.Smart
          anchors.bottom: scene.bottom
          anchors.horizontalCenter: scene.horizontalCenter
        }
      }
    }

    Cheers,
    Alex

     

    #5849

    Raimonds

    Thanks for quick response, Alex!

    I did what you said – Empty screen – no sign of AdMob component :(

     

    Raimonds

    #5850

    Alex
    V-Play Team

    This is kinda strange, do you have any other devices you could test it on?

    The easiest way to get log output from your Android device is to install the ADT Bundle (Android SDK + eclipse with Android plugins)
    http://developer.android.com/sdk/index.html

    Download -> extract -> start eclipse -> go to Window>Show View>Other>Android>Log Cat -> connect device via USB and done.

    Then you can filter for PID or Application Identifier of your game (with level verbose). This output would really help debugging your devices issues.

    Anyway i will try some more devices and see if i can encounter a similar problem.

    Cheers,
    Alex

Viewing 15 posts - 1 through 15 (of 18 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support