2017-02-25 45 views
0

我試圖integrade谷歌AdMobs到我的應用程序。如果我試圖整合谷歌AdMobs我的應用程序崩潰

我寫在我的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> 

這在我的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); 

我已經在集成

  1. compile 'com.google.android.gms:play-services-ads:10.2.0'在我的build.gradle
  2. <string name="banner_ad_unit_id">*censored*</string>我的string.xml
  3. <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>在我的清單。

我認爲問題是在我的MainActivity或我的XML。

爲什麼我的應用程序崩潰?

〜Aaron

+0

我得到的唯一的事情是這樣的,我的logcat:'3月2日至25日:01:51.103 12385-12385 /? I/art:延遲啓用-Xcheck:jni 02-25 03:01:51.198 12385-12385/com.aaron.waller.angelasound W/System:ClassLoader引用未知路徑:/data/app/com.aaron.waller .angelasound-2/LIB/arm64 3月2日至二十五日:01:51.659 12385-12385/com.aaron.waller.angelasound I /過程:發送信號。 PID:12385 SIG:9' –

+0

嘗試改變com.google.android.gms:發揮服務的廣告:10.2.0至com.google.android.gms:發揮服務的廣告:9.8.0或更早的版本。看看這是否有幫助,如果你有其他谷歌依賴項,請確保它們是9.8.0等。如果這不起作用,我會盡快將Google AdMob添加到一個新項目中,看看有什麼問題 – user7568042

+0

我將10.2.0更改爲9.8.0,但仍然存在相同問題:/ –

回答

1

我想你還沒有初始化移動廣告。 中的onCreate加載廣告之前加入這個...

MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); 
相關問題