build.gradle(モジュール)
...
dependencies{
...
implementation 'com.google.android.gms:play-services-ads:19.6.0'
...
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest/>
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
<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="ca-app-pub-3940256099942544/6300978111"/>
</RelativeLayout>
MainActivity.kt
class MainActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//追加
MobileAds.initialize(this)
val adView = findViewById<AdView>(R.id.adView)
adView.loadAd(AdRequest.Builder().build())
}
}