Adding AdMob banner causes infinite GCAndroid deconstrcutor - android

After Admob banner loaded, LogCat console begins to show GCAndroid deconstrucor lines non-stop:
Even if i close my app it still continues.
I'm using Eclipse with targeting Andoid SDK 21, min SDK is 11. Google Play Service included as project as per AdMob guide. Play Service SDK ver 6.5.
This is just for test and simply copied from Android Developer Training guide
package com.example.admob;
import com.google.android.gms.ads.*;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Main extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}
and layout is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="#string/admob_banner_id"
ads:adSize="BANNER" />
</LinearLayout>

The logcat lines are Android garbage collector. It just means that the garbage collector is running regularly. Nothing to be concerned about.
I suspect that if you comment out adView.loadAd(adRequest) you will still see them.

Related

Campaign Ads (House Ads)

my admob ads works perfectly (mediation by admob, running like 7 activities where i have these ads) but when i started campaign in one of my activity with one simple AD (320x50) it doesnt show. Tried every type of campaign noone worked.
Is there anything what i need to do? Something in code? or in Admob settings (except cpm, chose which activity, type of AD etc... already done that). I was searching for this problem the whole week but didnt find any succes.
If someone could help me it will be awesome because there is no support on AdMob except of FAQ which tells you nothing.
There is a sample of code activity and layout:
<LinearLayout
android:id="#+id/tejbl_tlacitka"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:orientation="vertical"
>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
style="#style/bannerpozadi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4412963312739253/5142509411" />
</LinearLayout>
Activity:
public class oAplikaciActivity extends AppCompatActivity {
private AdView mAdview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_oaplikaci);
setTitle("O aplikaci");
mAdview = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdview.loadAd(adRequest);

my ads are not showing up

i am just trying to learn how to add ads in android app.but the ads are not showing up.i don't know why its not coming up
here is my mainactivity.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_marginTop="443dp"
android:layout_below="#+id/textView"
android:layout_alignParentEnd="true">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Mainactivity.java
package com.example.a1407268.admob;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
If you're testing your app then use addTestDevice() to check Ad alignment.
AdView adView = new AdView(this);
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adView.loadAd(adRequestBuilder.build());
Otherwise If your App is live then and not able to show any Ad then you've to wait for some time.
According to Google
"It could be that you have only recently created a new Ad Unit ID and
requesting for live ads. It could take a few hours for ads to start
getting served if that is that case. If you are receiving test ads
then your implementation is fine. Just wait a few hours and see if you
are able to receive live ads then. If not, can send us your Ad Unit ID
for us to look into."
https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/fBe3YL3ffpo

java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView Error

I've seen similar questions but they couldnt solve my problem. I've installed Google Play SDKs, imported as a library to my app. Following Admob instructions, I've written that code below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.oguz.nfcdatareaderwriter.MainPage$PlaceholderFragment" >
<Button
android:id="#+id/writeNFC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/openingMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp"
android:text="Write Custom Data to a Card" />
<TextView
android:id="#+id/openingMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="174dp"
android:text=".."
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Main Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main_page);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relative);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("4df1dccd39006f0f")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
If you are getting NoClassDefFoundError then you have not properly included the GooglePlayServices library, or you have managed to exclude the classes using Proguard or similar. Try redoing the steps.
For me it was quite difficult to use AdMob with Eclipse LUNA and the last SDK and ADT.
What I've found it's that you must order your Java Build Path (Right Click then properties) as folow :
Android Dependecies checked, Android xxx Unchecked, Android Private Librairies Checked
And control that in your libs folder the google-play-services.jar is inside !

Ad is not appear

I would like to run an google developers example app which I have got from
here
I have registred at admobs.com from where I have my Ad unit ID which is in form: ca-app-pub-7.../... In main.xml I have then replaced AD_UNIT_ID_GOES_HERE for this new Ad unit ID.
Then I have replaced in main.xml TEST_DEVICE_ID_GOES_HERE for device id I have got from logcat:
09-07 19:49:30.881: I/Ads(5735): To get test ads on this device, call adRequest.addTestDevice("EFEA76C9D061FDD37B8ABF6EB712A991");
Also in BannerSample.java I have add code into onCreate:
package com.google.example.ads.xml;
import com.google.ads.AdRequest;
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.
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("EFEA76C9D061FDD37B8ABF6EB712A991");
}
}
I waited few minutes and App was running but ads banner is not appear.
Logcat:
09-07 20:32:01.037: W/webcore(5945): Can't get the viewWidth after the first layout
09-07 20:33:00.306: I/Ads(5945): AdLoader timed out after 60000ms while getting the URL.
09-07 20:33:00.310: D/webviewglue(5945): nativeDestroy view: 0x1cb198
09-07 20:33:00.322: I/Ads(5945): onFailedToReceiveAd(A network error occurred.)
I have I also tried already add code to manifest.(I have seen it there on stackoverflow but didn't worked).
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="pub-7..."
>
</meta-data>
I am using latest version GoogleAdMobAdsSdkAndroid-6.4.1. Thanks for any suggestions.
EDIT:
I have tried my app on emulator and other phone and there was no problem. Ad banner was showing fine. Phone where banner isn't appearing is Samsung I5801 with android 2.3.7. It is not my phone originally and it is probably rooted phone what could be reason, but I am not sure(I have found it on forum).
Try
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
}
in Main Layout add
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
and
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="YOUR_KEY"
ads:refreshInterval="32" />
Hope that helps :)
You can define your admob id in a string, along with all test devices for easy access
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/myAdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="#string/admob_id"
googleads:testDevices="#string/ADS_TEST_DEVICES" />
Then in your activity:
package com.google.example.ads.xml;
import com.google.ads.AdRequest;
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);
AdView myAdView = (AdView) this.findViewById(R.id.myAdView);
AdRequest request = new AdRequest();
myAdView.loadAd(adRequest);
}
}
Happy Coding!
You may forget to Add permissions on your Android maifest file. Seems like that
INTERNET and
ACCESS_NETWORK_STATE permissions are required in your Android manifest closer to your manifest tag.
The message: There was a problem getting an ad response. ErrorCode: 1 reffers that the ad unit ID is invalid.
public static final int ERROR_CODE_INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
Constant Value: 1 (0x00000001)
The solution is changing the ad unit ID.

weird admob problem

I did some updates to my application today but now admob dont work right and it gives me an error in the ad saying adview missing xml attribute "adsize". now the changes i made have nothing to do with the ads and they have been the same since I implemented them and worked
this is my xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.notify.me.lite"
android:layout_width="fill_parent"
android:id="#+id/mainLayout1"
android:layout_height="fill_parent" android:orientation="vertical">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="id"
ads:adSize="BANNER"/>
<WebView android:layout_width="fill_parent" android:id="#+id/webView1" android:layout_height="fill_parent"></WebView>
</LinearLayout>
and where its implemented
public class Main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_webview);
WebView browser = (WebView) findViewById(R.id.webView1);
browser.loadUrl("file:///android_asset/about.html");
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
as you can see adsize is there in the xml file so there should be no reason why I should be getting that error. Ideas as to why this is happening all of the sudden?
Google updated the AdMob library but did not yet document the required changes, as per this forum thread
The substance of the change is to update the ads namespace:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
No idea why its suddenly stoped working but whenever i use Admob i always put it in a seperate layout, with xml like:
<RelativeLayout android:id="#+id/rLayAdMob"
android:layout_width="match_parent" android:layout_height="50dip">
</RelativeLayout>
Then in the onCreate function i setup the adView like:
adView = new AdView(Menu.this, AdSize.BANNER, MY_AD_UNIT_ID);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.rLayAdMob);
layout.addView(adView);
I've never had any issues doing it this way, and would only require a small change to your code.
Hope this helps,
Kenny

Categories

Resources