Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had exactly the same problem with getting the "you must have AdActivity declared in AndroidManifest.xml with configChanges." error message after integrating the latest AdMob SDK. Even though I have found this and the other two related discussions (see links at the bottom of this article) at StackOverflow, they didn't help me to solve the issue, as -- for me -- they did not differentiate clear enough between the <code>targetSdkVersion</code> attribute in the manifest and the build target. This answer describes what solved the issue for me and what caused trouble.</p> <h2>Solution</h2> <p>The easiest part at first: you are missing a few flags in the <code>configChanges</code> attribute of the definition of the <code>AdActivity</code> in your <code>AndroidManifest.xml</code>. As shown in the <a href="http://code.google.com/intl/de-DE/mobile/ads/docs/android/fundamentals.html" rel="nofollow noreferrer" title="AdMob SDK Docs">AdMob SDK Docs</a> the definition needs to look like this:</p> <pre><code>&lt;activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/&gt; </code></pre> <p>The second -- and more complicated part -- is related to the SDK target: The only solution that really seems to work is to use the SDK manager to install the SDK for at least Android 3.2 (API level 13). After you have installed this SDK version you need to configure your IDE to build your project using this SDK. The exact setting depends on the IDE you are using. In my case it is IntelliJ IDEA and there you will find the option in the project settings on the <em>Project</em> page below the headline <em>Project SDK</em>.</p> <p>You should also adjust the <code>target</code> property in your project's <code>project.properties</code>. This is at least important if you are building your release using ANT. The line should look like this:</p> <pre><code>target=android-13 </code></pre> <p><strong>The configuration above alone does the trick. There are <em>no</em> changes required to the <code>&lt;uses-sdk&gt;</code> element in the AndroidManifest. Read the pitfalls below to learn why this may cause trouble.</strong> </p> <h2>Explanation</h2> <p>The build target and the <code>&lt;uses-sdk&gt;</code> elements have completely different scopes. </p> <p>The <strong>build target</strong> is evaluated <em>only</em> at build time by your build tools to determine which version of the SDK tools on your system should be used to build your app. The newer the SDK the more API features does it know. Out of whatever reason Google forces us to specify some <code>configChanges</code> which aren't available before API level 13 and so we need to build our app using at least the SDK tools 13 because a previous version of the SDK tools does not know these new <code>configChanges</code> and will report an error. At runtime the build target does not have any meaning and Android will ignore all elements (e.g. in <code>configChanges</code>) which it does not know.</p> <p>The <strong>targetSdkVersion</strong> element specified on the <code>&lt;uses-sdk&gt;</code> element in the android manifest in contrast is <em>only</em> evaluated at run time -- <em>not</em> at compile time. In fact you can specify any value you want here without the compiler changing anything or bringing up an error message. This is why changing this attribute does not help us to solve our AdMob problem. On the other hand at runtime the attribute may be evaluated by android to support some compatibility features for apps which have been build for older android versions. See the pitfalls section below to see a topic which caused trouble for me.</p> <h2>Pitfalls</h2> <ul> <li><strong>Do <em>not</em> change set <code>targetSdkVersion</code> to a higher version if you are not able to test your app on this android version:</strong> Because I have misunderstood the existing answers regarding this admob topic I have also set the <code>android:targetSdkVersion</code> attribute of the <code>&lt;uses-sdk&gt;</code> element to API level 13 in my app which caused a fatal side effect: As Android 3 thought my app would natively support honeycomb, it did no longer show the menu button in the soft button bar at the bottom border and as my app hides the native title bar to show it's own implementation the user did not have any possibility to access the menu any more on honeycomb. So for me leaving the <code>targetSdkVersion</code> at level <code>10</code> helped to bring back the menu button and worked fine.</li> <li><strong>Handling backward compatibility to older APIs which may be lost in SDK tools 13:</strong> OK, so I have set my build process to use the SDK tools 13 and my <code>targetSdkVersion</code> to 10 and everything should be fine, right? Unfortunately not! The reason is, that my app is compatible downwards to Android 1.5 (API level 3) as this still makes up about 5% of my users. Unfortunately after setting the build target to 13 some parts of my code did not compile any more as they referenced deprecated methods which were supported until SDK tools 10 but no longer starting with SDK tools 11 (e.g. <code>Service.setForeground</code>). </li> </ul> <p>The basics how to handle backwards compatibility are described <a href="http://developer.android.com/resources/articles/backward-compatibility.html" rel="nofollow noreferrer" title="here">here</a> -- but this article does not describe how to call deprecated methods which are no longer available as they will cause a compiler error. I solved this by creating a new library project used by my app. For this library project I have set the build target back to 10 which will cause it to be compiled using the SDK tools 10 which still know about the android deprecated API I am using. My app then calls helper methods from this compatibility library and so I can compile my app with a newer target SDK.</p> <hr> <h2>Related Topics</h2> <p>Here the list of the other related discussions I have found:</p> <ul> <li><a href="https://stackoverflow.com/q/7902121/280384">AdMob can&#39;t display ads because of configChanges</a></li> <li><a href="https://stackoverflow.com/q/7901018/280384">AdMob SDK 4.3.1 - I can&#39;t display banner</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload