0

I tried to integrade Google AdMobs into my application.

I wrote that in my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.ads.AdView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:id="@+id/adView"></com.google.android.gms.ads.AdView>

And this in my MainActivity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AdView adView = (AdView)findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

I already integrated

  1. compile 'com.google.android.gms:play-services-ads:10.2.0' in my build.gradle
  2. <string name="banner_ad_unit_id">*censored*</string> in my string.xml
  3. <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> in my Manifest.

I think the problem is either in my MainActivity or in my XML.

Why does my app crash?

~Aaron

Aaron Waller
  • 175
  • 4
  • 21
  • The only thing i get is this in my Logcat: `02-25 03:01:51.103 12385-12385/? I/art: Late-enabling -Xcheck:jni 02-25 03:01:51.198 12385-12385/com.aaron.waller.angelasound W/System: ClassLoader referenced unknown path: /data/app/com.aaron.waller.angelasound-2/lib/arm64 02-25 03:01:51.659 12385-12385/com.aaron.waller.angelasound I/Process: Sending signal. PID: 12385 SIG: 9` – Aaron Waller Feb 25 '17 at 02:02
  • Try changing com.google.android.gms:play-services-ads:10.2.0 to com.google.android.gms:play-services-ads:9.8.0 or earlier versions. See if this helps and if you have other google dependencies, make sure they are 9.8.0, etc too. If that doesn't work, I'll have a shot at quickly adding Google AdMob to a new project and see whats the issue – user7568042 Feb 25 '17 at 02:12
  • I changed 10.2.0 to 9.8.0 but its still the same problem :/ – Aaron Waller Feb 25 '17 at 02:34
  • You should be getting an error log if the app crashes. Try to debug and get the error log. Only it helps – Arun Shankar Feb 25 '17 at 02:53
  • @Arun Electra This is my whole Logcat: https://gyazo.com/cf8417b923b92382490f38790338ab8d And this is my whole Debug: https://gyazo.com/76cd7f3e068c983d37e575f144593cd8 – Aaron Waller Feb 25 '17 at 03:04
  • You can follow this tutorial it will help you. [Android Studio AdMob](https://firebase.google.com/docs/admob/android/quick-start) – Asif Raza Feb 25 '17 at 03:59
  • @AaronWaller Android Studio is not catchind your logcat. Look at the Logcat window, the connection shows "DEAD". And, in the debug, your app started at 04:03, but your logcat only shows till 04:02 I think your log cat is not catched by Android Studio, please check – Arun Shankar Feb 25 '17 at 07:03
  • I found the problem, the code i put in my XML was in my fragment.xml and not in my content_main.xml :) – Aaron Waller Feb 25 '17 at 12:20

1 Answers1

1

I think you had not initialized Mobile ads. Add this in onCreate before loading ad...

 MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
Saurabh
  • 41
  • 3