[英]Can't get Admob to work
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
It says cannot resolve symbol AdRequest and cannot resolve Adview. 它说无法解析符号AdRequest,也无法解析Adview。 What am I doing wrong?
我究竟做错了什么? Included the following in my main activity file
在我的主要活动文件中包含以下内容
<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>
Also, I've added the following to Build.gradle 另外,我在Build.gradle中添加了以下内容
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
}
I want to display Banner Ads on my app and I'm using Admob for the first time. 我想在我的应用上显示横幅广告,并且我是第一次使用Admob。 Added above codes from google dev website.
从Google开发者网站添加了以上代码。 In the app's project structure, I've also enabled Admob.
在应用程序的项目结构中,我还启用了Admob。
EDIT 编辑
I now know what's the problem but cannot fix it. 我现在知道有什么问题,但无法解决。 I've enabled Admob from Project Structure and it has added
我已经从Project Structure启用了Admob,它已经添加了
compile 'com.google.android.gms:play-services:8.4.0'
in the build.gradle. 在build.gradle中。 I've checked a banner example, Example has play-services in external libraries but it doesn't show up in my app.
我已经检查了一个横幅示例,Example在外部库中具有播放服务,但未在我的应用中显示。
In my app, play-services only shows up in build.gradle but not in the External Libraries. 在我的应用中,播放服务仅显示在build.gradle中,而不显示在外部库中。 I only see Android API 23 Platform, < 1.8 >, android-android-23 and support-annotations in my External Libraries column.
我在“外部库”列中仅看到Android API 23 Platform,<1.8>,android-android-23和support-annotations。 I tried cleaning the project, rebuilding and also tried Invalidate cache/ Restart.
我尝试清理项目,重建,还尝试了使缓存无效/重新启动。 None of them worked.
他们都没有工作。 Any suggestions?
有什么建议么?
I had same issue in my last project and I solved it like this 我在上一个项目中遇到了同样的问题,我像这样解决了它
Goto Build
menu 转到
Build
菜单
Click on Clean Project
点击
Clean Project
let it finish then Build
menu again and hit Rebuild Project
让它完成,然后再次
Build
菜单,然后单击“ Rebuild Project
If this didn't solve it. 如果这不能解决问题。
Try this 尝试这个
you need to edit your manifest file 您需要编辑清单文件
ad this after application
tag 在
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" />
EDIT 编辑
Download this example provided by google in their tutorial here and see if it works or not and let us know what was the result 下载这个例子由谷歌提供在他们的教程这里 ,看看是否可行与否,让我们知道结果是什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.