简体   繁体   English

无法广告Google AdView

[英]Unable to ad Google AdView

USing Android Studio 2 I get this error while compiling the code 使用Android Studio 2编译代码时出现此错误

Gradle: Execution failed for task ':dummy002:compileDebug'. Gradle:任务':dummy002:compileDebug'的执行失败。

Compilation failed; 编译失败; see the compiler error output for details. 有关详细信息,请参见编译器错误输出。 C:\\Android_XML\\dummy002Project\\dummy002\\src\\main\\java\\com\\example\\dummy002\\MainActivity.java\\ Gradle: package com.google.ads does not exist C:\\ Android_XML \\ dummy002Project \\ dummy002 \\ src \\ main \\ java \\ com \\ example \\ dummy002 \\ MainActivity.java \\ Gradle:包com.google.ads不存在

I have add the file GoogleAdMobAdsSdk-6.4.1.jar in the lib directory and also as library file. 我在lib目录中也将文件GoogleAdMobAdsSdk-6.4.1.jar添加为库文件。

When coding the code does not show any error highlight. 编码时,代码不会突出显示任何错误。

If I use the AdView in Actitvity the preview in studio show banner ads by google. 如果我在Actitvity中使用AdView,则Studio中的预览会显示Google的横幅广告。

Where am I going wrong. 我要去哪里错了。

添加依赖项build.gradle文件中的行解决了该问题

"compile fileTree(dir: 'libs', include: '*.jar')"
adView = new AdView(this, AdSize.BANNER, "your key");        

AdRequest request = new AdRequest();
request.setTesting(false);
adView.loadAd(request);

XML File
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId=" a1510b619xxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM