I followed this tutorial on how to add AdView
https://developers.google.com/mobile-ads-sdk/docs/
By adding this to my 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"/>
And this to build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
}
And to my java file:
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);
}
}
But whenever I open the activity it crashes
logcat:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView