1

I have created a paid application and I'm trying to create the free with admob ads. I setup the entire proyect as explained on Google's tutorial with SDK 6.1, but when running it doesn't work.

The code I have used is the same as the tutorial: Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/hello"/>
    <com.google.ads.AdView android:id="@+id/ad"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adSize="BANNER"
                           ads:adUnitId="xxxxxxxxxx" 
                           ads:loadAdOnCreate="true"/>
</LinearLayout>

BannerSample.java package com.google.example.ads.xml;

import android.app.Activity;
import android.os.Bundle;

/**
 * A simple {@link Activity} which embeds an AdView in its layout XML.
 */
public class BannerSample extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // This example requires no additional code since the optional
    // "loadAdOnCreate=true" XML attribute was used. If "loadAdOnCreate" were
    // not specified, the ad would have to be loaded by creating an AdRequest
    // and using Activity.findViewById() to get the AdView.
    //
    // The "loadAdOnCreate" XML attribute makes it simpler to get ads since no
    // code is required, but it also limits the developer's control over the ad
    // request since a generic AdRequest is used.
  }
}

The errors I get:

07-28 21:34:48.704: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:34:48.704: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:36:48.841: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:36:48.841: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:38:48.958: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:38:48.958: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:40:49.066: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:40:49.066: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:42:02.817: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:02.827: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:03.178: E/Ads(17098): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:42:03.198: E/Web Console(17098): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1

Thanks for the help!

UPDATE: New code and erros are: BannerSample.java

package com.google.example.ads.xml;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;

/**
 * A simple {@link Activity} which embeds an AdView in its layout XML.
 */
public class BannerSample extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // This example requires no additional code since the optional
    // "loadAdOnCreate=true" XML attribute was used. If "loadAdOnCreate" were
    // not specified, the ad would have to be loaded by creating an AdRequest
    // and using Activity.findViewById() to get the AdView.
    //
    // The "loadAdOnCreate" XML attribute makes it simpler to get ads since no
    // code is required, but it also limits the developer's control over the ad
    // request since a generic AdRequest is used.
    (new Thread() {
        public void run() {
             Looper.prepare();
             AdView view = (AdView) findViewById(R.id.ad);
             view.loadAd(new AdRequest());
        }
    }).start();
  }
}

Errors:

07-28 21:42:02.817: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:02.827: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.

UPDATE 2: Sorry I forget to post the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.google.example.ads.xml"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:targetSdkVersion="15" android:minSdkVersion="3"/> 

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <meta-data android:value=" a1501435dfa5050 " android:name="ADMOB_PUBLISHER_ID" />
        <activity android:name=".BannerSample"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.google.ads.AdActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>
droidpl
  • 5,872
  • 4
  • 35
  • 47
  • Ok, AFMA_getSdkConstants error is solved with a different thread because Android 4.0+ doesn't support internet connections on main thread, but the StatHub::Init error is still there – droidpl Jul 28 '12 at 19:54
  • What about your Manifest. Post it here. – Ahmad Jul 28 '12 at 21:57
  • Thanks for your interest, I have posted the manifest as you asked. I can add to those information that everything works on the emulator, but this error is displayed when I export the application into my phone - HTC Desire S – droidpl Jul 29 '12 at 10:11
  • This is weird - I thought it was the opposite, that AdView.loadAd HAD to be done on the main thread. You shouldn't need the publisher ID in your manifest; you should put that ID directly into your XML. Also, what happens if instead of loading an ad in code, you to it in XML by adding `ads:loadAdOncreate="true"`? – Eric Leichtenschlag Jul 30 '12 at 18:15
  • Happends the same. Know I'm thinking it could be a problem related to the custom ROM I installed on the device. I'm Trying to install another rom, and if it is solved, I'll tell you (and developers of the Rom to solve this issue). – droidpl Jul 30 '12 at 22:01
  • Developers tell me it's a problem on my program in UIThread permissions, that might use StrictMode policies to solve it, but no results. Any idea? – droidpl Aug 08 '12 at 20:34

2 Answers2

1
(new Thread() {
            public void run() {
                 Looper.prepare();
                adView.loadAd(new AdRequest());
            }
        }).start();

In ICS you're not allowed to perform network operation in the main thread

Nam Vu
  • 5,669
  • 7
  • 58
  • 90
  • Right now the loadAd operation is performed on a separate thread. Nevertheless, I have tried it and it is still not working. Look at the second update to see the errors. – droidpl Sep 25 '12 at 10:54
  • Found a contradicting answer: http://stackoverflow.com/questions/12316995/how-to-load-admob-ads-in-new-thread "The loadAd call needs to happen on the UI thread, because the SDK will eventually be adding the to your view hierarchy." Who's right? – Rooster242 Oct 11 '12 at 06:07
  • 1
    This is not true. You must start do this on the UI thread, otherwise it crashes. – grebulon Dec 20 '12 at 21:51
0

You wouldn't believe this, but we were getting this error on one very specific device (HTC Desire C) when the loaded page had a bad DOM structure. We could reproduce it with the following broken HTML:

<html>
    <body></body>
</html>
Hello world!
</html>

The app would crash without any stack trace, but several logs similar to:

E/chromium(14074): external/chromium/net/disk_cache/stat_hub.cc:190: [1026/182205:ERROR:stat_hub.cc(190)] StatHub::Init - App com.myapp isn't supported.
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • The mine is HTC Desire S, it seems is a problem on HTC that an be reproduced using admob maybe. – droidpl Oct 28 '12 at 15:30
  • I'm not particularly familiar with how Admob works. Do the ads appear in a WebView? We've been experiencing very difficult to reproduce crashes on both the HTC Desire HD and the HTC Desire C related to long lines in the HTML. – Paul Lammertsma Oct 29 '12 at 11:39
  • I've [opened a new question concerning my issue](http://stackoverflow.com/questions/13121158/webview-and-native-browser-crash-on-simple-html). Perhaps you can test this on your device to see if the simple test case also crashes as I suspect the issues might be related. – Paul Lammertsma Oct 29 '12 at 11:59
  • @PaulLammertsma Is there a workaround for this? I'm trying to get adverts to show on my HTC Desire HD with the same errors. The adverts show up on my stock Nexus7 and in the emulators. – RED_ Jan 19 '13 at 10:49
  • Not that I'm aware of. It should really be HTC's responsibility to fix it, but it's fairly unlikely they will for those old devices. You could consider filling an issue with them, but aside from that I don't have any suggestions. – Paul Lammertsma Jan 20 '13 at 01:12