애드몹에 배너 광고 등록 후
* 애드몹을 이용하기 위해선 SDK Manager 에 Google Repository가 설치되어 있어야 합니다.
Tools - Android - SDK Manager - SDK Tools - Google Repository
1. project 레벨 gradle 수정
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
2. app 레벨 gradle sdk 추가
compile 'com.google.android.gms:play-services-ads:10.0.1'
3. 매니페스트 수정
[권한 추가]
<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" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value=“ADMOB_APP_ID”/>
-> 애드몹에 등록된 앱 ID
[구글 애드몹 액티비티 추가]
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
4. strings.xml 추가
<string name="banner_ad_unit_id">배너 광고 단위 id</string>
<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">
[oncreate]
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
애드몹 에러코드
0: 앱에 등록한 광고 아이디와 애드몹에서 생성된 광고 아이디가 다를 때 나는 오류
1 : 광고 아이디의 '~' 부분을 '/' 로 변경 안해서 나는 오류