前提・実現したいこと
AndroidStudioでアプリ開発を行っています。
自作のアプリに広告をつけようとAdMobに登録し、広告配信可能のメールも受け取ったのですが、Playストアで配信されている自分のアプリをインストールしてみても広告が表示されません。
広告タイプはバナーで広告ユニットIDもアプリIDもちゃんと所定の箇所に入力しています。
デバッグ段階で署名付きのビルドを行うと実機で本番の広告(マクドナルドやGooglePlayなど)が表示されるのですが、いざリリースしてみると何も表示されません。
Androidでアプリをリリースするのは初めてで、デバッグとリリースで違うところなどをまだ把握しきれていません。Proguardの記述やFirebaseの証明書など何か気を付けるべきことがあれば教えてください。
該当のソースコード
main_activity.xml
xml
1 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 7 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 8 xmlns:ads="http://schemas.android.com/apk/res-auto" 9 android:layout_width="match_parent" 10 android:layout_height="0dp" 11 android:layout_weight="1" 12 android:orientation="vertical"> 13 14 <!--ボタンなどいろいろ--> 15 16 </LinearLayout> 17 18 19 <com.google.android.gms.ads.AdView 20 xmlns:ads="http://schemas.android.com/apk/res-auto" 21 android:id="@+id/adView" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:layout_gravity="center_horizontal|bottom" 25 ads:adSize="BANNER" 26 ads:adUnitId="@string/banner_ad_unit_id"> 27 </com.google.android.gms.ads.AdView> 28 29</LinearLayout> 30
MainActivity.java
java
1 2 @Override 3 protected void onCreate(Bundle savedInstanceState) { 4 super.onCreate(savedInstanceState); 5 setContentView(R.layout.activity_main); 6 MobileAds.initialize(this, "<<自分のアプリID>>"); 7 mAdView = (AdView) findViewById(R.id.adView); 8 AdRequest adRequest = new AdRequest.Builder().build(); 9 mAdView.loadAd(adRequest);
build.gradle(app)
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.hatenablog.tetsudo_ide.trainjourny" minSdkVersion 24 targetSdkVersion 27 versionCode 9 versionName "1.05" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.google.android.gms:play-services-maps:16.0.0' implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.android.gms:play-services-ads:17.1.1' implementation 'com.google.firebase:firebase-ads:17.1.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } apply plugin: 'com.google.gms.google-services'
試したこと
・network_security_config.xmlの削除
広告の通信がこれで妨害されると思ったが、署名付きデバッグタイプビルドで実機で問題なく本番広告が表示されたので問題の要因ではないと判断したため元に戻した。
・Google公式のバナー広告サンプルのproguard-rules.proのコピペ
GithHubで公開されているバナー広告サンプルのproguard-rules.proをコピペしてみたが、本番の広告は表示されなかった。クラス名などについて知識不足なのでオリジナルから変更すべき点があるかもしれない。
補足情報
テスト広告は実機もエミュレータも問題なく表示されます。
AdMob側でPlayストアに登録されているアプリとリンク済みです。
FirebaseのプロジェクトもAdMobとリンク済みです。
AdMobとFirebaseはアプリのリリース前に導入しました。
FirebaseでもAdMobでもアプリの解析(アクティブユーザー数や広告のリクエスト回数の調査)ができています。
該当のアプリ:
https://play.google.com/store/apps/details?id=com.hatenablog.tetsudo_ide.trainjourny
あなたの回答
tips
プレビュー