[英]Can't get Admob to work
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
它說無法解析符號AdRequest,也無法解析Adview。 我究竟做錯了什么? 在我的主要活動文件中包含以下內容
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView><com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
另外,我在Build.gradle中添加了以下內容
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
}
我想在我的應用上顯示橫幅廣告,並且我是第一次使用Admob。 從Google開發者網站添加了以上代碼。 在應用程序的項目結構中,我還啟用了Admob。
編輯
我現在知道有什么問題,但無法解決。 我已經從Project Structure啟用了Admob,它已經添加了
compile 'com.google.android.gms:play-services:8.4.0'
在build.gradle中。 我已經檢查了一個橫幅示例,Example在外部庫中具有播放服務,但未在我的應用中顯示。
在我的應用中,播放服務僅顯示在build.gradle中,而不顯示在外部庫中。 我在“外部庫”列中僅看到Android API 23 Platform,<1.8>,android-android-23和support-annotations。 我嘗試清理項目,重建,還嘗試了使緩存無效/重新啟動。 他們都沒有工作。 有什么建議么?
我在上一個項目中遇到了同樣的問題,我像這樣解決了它
轉到Build
菜單
點擊Clean Project
讓它完成,然后再次Build
菜單,然后單擊“ Rebuild Project
如果這不能解決問題。
嘗試這個
您需要編輯清單文件
在application
代碼之后投放此廣告
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
編輯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.