我遵循了关于如何添加AdView的本教程
https://developers.google.com/mobile-ads-sdk/docs/
通过将其添加到我的AndroidManifest.xml中:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|sm allestScreenSize"/>这是给build.gradle的
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
}对于我的java文件:
import com.google.android.gms.ads.*;
public class admob extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admoblayout);
// Create an ad.
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("My_UnitID_Here");
RelativeLayout layout = (RelativeLayout) findViewById(R.layout.admoblayout);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}}
但是每当我打开活动它就会崩溃
logcat:
FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView
发布于 2014-03-14 13:05:39
有时,当添加新的布局,甚至修改现有布局时,IDE需要对项目进行刷新才能生效。
一旦您刷新/重建了项目,您就可以继续了。
https://stackoverflow.com/questions/22363787
复制相似问题