Admob implementation Error - android

I got a Problem with implementing Admob into an App.
This is my main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
and this is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ollidiemaus.testmob"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".TestAdmobActivity" >
<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"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
And finaly this is my Activity:
public class TestAdmobActivity extends Activity {
private AdView adView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "a14ead58dc2a456");
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout1);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());}
#Override
public void onDestroy() {
adView.destroy();
super.onDestroy();
}}
Now when i'll start the app in the AdView is an error called: "you must have AdActivity declared in AndroidManifest.xml with configChanges."
I used Android 4.0 so above 3.2 but it is not working.
I hope anyone could help me.

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 targetSdkVersion attribute in the manifest and the build target. This answer describes what solved the issue for me and what caused trouble.
Solution
The easiest part at first: you are missing a few flags in the configChanges attribute of the definition of the AdActivity in your AndroidManifest.xml. As shown in the AdMob SDK Docs the definition needs to look like this:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
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 Project page below the headline Project SDK.
You should also adjust the target property in your project's project.properties. This is at least important if you are building your release using ANT. The line should look like this:
target=android-13
The configuration above alone does the trick. There are no changes required to the <uses-sdk> element in the AndroidManifest. Read the pitfalls below to learn why this may cause trouble.
Explanation
The build target and the <uses-sdk> elements have completely different scopes.
The build target is evaluated only 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 configChanges 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 configChanges and will report an error. At runtime the build target does not have any meaning and Android will ignore all elements (e.g. in configChanges) which it does not know.
The targetSdkVersion element specified on the <uses-sdk> element in the android manifest in contrast is only evaluated at run time -- not 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.
Pitfalls
Do not change set targetSdkVersion to a higher version if you are not able to test your app on this android version: Because I have misunderstood the existing answers regarding this admob topic I have also set the android:targetSdkVersion attribute of the <uses-sdk> 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 targetSdkVersion at level 10 helped to bring back the menu button and worked fine.
Handling backward compatibility to older APIs which may be lost in SDK tools 13: OK, so I have set my build process to use the SDK tools 13 and my targetSdkVersion 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. Service.setForeground).
The basics how to handle backwards compatibility are described here -- 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.
Related Topics
Here the list of the other related discussions I have found:
AdMob can't display ads because of configChanges
AdMob SDK 4.3.1 - I can't display banner

My solution to a similar case was to use
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="11" />
or just use android:targetSdkVersion= under 13

You also need to set the following permissions in your AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Then admob can assess the internet and also not show the ad when it has no internet connectivity.

Have you also set your build target to be higher than Android 3.2, i.e. in default.properties set target higher than android-13? Also make sure that you're using the latest version of the SDK.
PS! Don't expose your device ID to the public.

As you can see here, very few phones have Android versions of 3.x.x or higher installed
http://developer.android.com/resources/dashboard/platform-versions.html
Why would anybody want to compile their app to something few phones can handle? Either I am misunderstanding something or I will need to find some other ad company that doesn't require a newer Android version.

Above error occurs when you use the library GoogleAdMobAdsSdk-4.3.1.jar.
I've been that error and I've found this demo from Google.
I've replaced lib 4.3.1 by 4.0.3 in this demo and it runs OK.

if you use AndroidStudio and Gradle, you must also update the build.gradle file like this:
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 3
targetSdkVersion 17
}
...

Related

What's the usage of tools:targetApi="m"?

I have an app uses clearText between Android-client and server using Retrofit, and in Android 9+ it's not allowed to use clearText.
To ignore that I added android:usesCleartextTraffic="true" in Manifest but it warns: tools:ignore="GoogleAppIndexingWarning" and suggests to add tools:targetApi="m".
It's a bit confusing:
Is the tools:targetApi="m" means that any attributes with tools: is for Marshmallow and higher?
Is it for using this version of Manifest or something else? Is this making unwanted mistake in my app?
My Manifest:
...
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:fullBackupContent="false"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="false"
android:theme="#style/AppTheme.NoActionBar"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:targetApi="m">
...
From the docs you can read:
Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is
This means it will affect only the annotated one.
Other attributes with tools won't be affected. tools is a namespace, from which you can get attributes, an attribute won't affect the entire namespace.
By adding tools:targetApi="m" to an element you tell the lint that the element won't be used on API level below 23 (M). See the attribute documentation.
This tells the tools that you believe this element (and any children) will be used only on the specified API level or higher. This stops lint from warning you if that element or its attributes are not available on the API level you specify as your minSdkVersion.
In this particular case <application> uses android:usesCleartextTraffic attribute which is available starting from API 23 but the app minSdkVersion is less then 23 so lint warns you. Despite specifying tools:targetApi removes the warning in this case it isn't a right solution because the <application> can be used on older API levels if minSdkVersion allows it. But such a trick won't harm because android:usesCleartextTraffic will be ignored if it isn't supported, see this answer for more details.
What about tools namespace in general, it contains attributes which used by build tools and won't affect runtime behavior. See the docs for more details.
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.

Using ActionBarSherlock in Mono Android

I am trying to implement the ActionBar in a Mono Android application. Could someone provide me steps to including the ActionBar project in my solution? I have seen the sample projected provided at this url
https://github.com/xamarin/monodroid-samples/tree/master/ActionBarSherlock
Do I have to simply add a reference of the ActionBarSherlock project in that sample? When I attempt to add a reference to that project I get many errors such as "Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Holo.Widget.ActionBar.Menu'." in file abs_styles.xml
Has anyone else successfully added ActionBarSherlock to a Mono Android Project? Could you please provide me steps to get a simple example working?
Ok, this is how I got it working...
Open up the sample project and build just the 'ActionBarSherlock' project on Release mode. Make sure that the minimum target android version is 4.0.3 (required)
Take the dll and reference it in your project. I have found that you can get it to compile fine if your project has a minimum android version of 2.2 - I found that if you used profile version 2.1 it doesn't work, but that just might of been my app. Maybe your minimum version is too low? I also set my 'target' android to be the latest... I don't know if this helps too.
The reason I say to reference the dll instead of the project is that you will get the correct intellisense. Otherwise as you can see in the example project it does not (Makes working on it a pain!).
Make sure you have a reference to the v4 support lib in your project (Mono.Android.Support.v4)
The final step is that need to change your default theme to use a Sherlock theme. (see xml below for example)
Use the ActionbarSherlock.* namespaces when adding Actionbars etc...
Example manifest after adding ActionbarSherlock:
<manifest ...>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<application android:label="IDNT" android:theme="#style/Theme.Sherlock.Light.DarkActionBar" android:icon="#drawable/Icon">
</application>
</manifest>
BEWARE: There is a small issue with all this... If your project has a minimum version of under 3.0 (ie 2.2 as per my example) and you compile with linking (ie SDK assemblies only) you will get an error 'Mono.Cecil.ResolutionException: Failed to resolve Android.Database.IDatabaseErrorHandler'. I am currently sending support messages about this to Xamarin and will edit this post once I work out a fix.
EDIT: To fix the issue I have mentioned above make sure that the project options -> Application -> Minimum Android to target option is at LEAST 4.0.3. Your minSdkVersion can still be 7/8 or whatever so it will still run in older android versions. It also means you have to be careful you dont code in stuff that is for higher versions.

Can I set API level X attributes in my manifest when my minSdkVersion is less than X?

I'm working on an Android application where I'd like to have the largeHeap and hardwareAccelerated flags on. However, it also needs to support Android 2.3.
My AndroidManifest.xml looks like the following:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10"/>
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:largeHeap="true"
>
However, Eclipse refuses to build the project, saying:
error: No resource identifier found for attribute 'hardwareAccelerated' in package 'android'
error: No resource identifier found for attribute 'largeHeap' in package 'android'
Raising the targetSdkVersion to 11, where such flags were introduced, does not solve the problem.
Is it possible to support Android 2.3 and still set these flags?
Yes you can add the XML attributes but you have to build with the required sdk level for those attributes. Older plattforms will just ignore those attributes. To do so change the Project Build Target to 11 in the project specific Android settings in Eclipse.
But pay attention, if you start building your project with sdk level 11 you could easily slip in code that does not execute on devices with level <11.
See Backward Compatiblity for an similar explanation on how to enable the installLocation attribute (introduced in level 8) and still build for sdk level less than 8.

Google Admob Integration Errors

I am working on an app for Android 2.2 Platform, wanted to integrate admob into it, StackOverflow I set up an account downloaded the latest admob SDK and created an ad Layout in XML followed the instructions mentioned in docs. I have set the target in project properties to 1.4 and set the min SDK to 8. Now the error occurs when I configure
<activity Android:name="com.Google.ads.AdActivity" Android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
The String
keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize
wont compile for Android 2.2 it throws errors. However if I compile without these screenSize|smallestScreenSize, it compiles but the ad area in the app shows an error saying You must have AdActivity declared in AndroidManifest with configChanges
Can you guys suggest a solution, any help with this problem is appreciated.
The Google AdMob SDK v4.3.1 requires the additional config changes for optimization on tablets that are running apps with Google AdMob Ads. The configChanges screenSize and smallestScreenSize were not introduced until android-13, so therefore the Google AdMob SDK requires you to COMPILE against Android 3.2 or greater.
You can still make your app run on Android 2.2 devices/emulators by setting the minSdkVersion in your manifest:
<uses-sdk android:minSdkVersion="8" />
set target in project.properties to android-13 (Android v3.2)
not in manifest! (this is that I misunderstood)

How i can migrate my app from 1.5 to 1.6 api fast and safe?

i am making a gigantic app for android, and i start doing it some moths ago for android 1.5, but now i know that some of the things i need for my app only can be done if you are programming for 1.6 api.
there is a easy, fast and safe way to migrate my app from 1.5 to 1.6 without having to lose time?
thanks
Since you are going to a newer version, I don't think that any code changes will be needed.
You need to:
1) Update the minSdkVersion in the AndroidManifest.xml. For android 1.6 it should be minSdkVersion = 4. If you don't have that already, it is a good practice to always include it in the manifest. Add this line:
<uses-sdk android:minSdkVersion="4" />
as the last line before the closing tag of the manifest.
2) Change the target (again to 4) in your IDE or ant build scripts. In Eclipse right click your project, select Properties, Android and change the Project Build Target. Your project will recompile, when you click the Apply button.
Then, do a re-compile. I don't expect any errors to occur, but if they do, they will only be a few and you will be able to correct them quickly.
I use the following in my manifest file:
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
At the same time I have configured Eclipse to use the Android 2.2 API. This way I ...
support small screens
can use the latest features (as long as I do it with care)
android 1.5 users can still use my app (as long as I make sure it degrades gracefully)
See http://developer.android.com/guide/appendix/market-filters.html

Categories

Resources