質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

1474閲覧

AndroidでAdMobアプリを作るとエラーになって落ちる

jmdajmw

総合スコア302

AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/09/18 23:48

編集2022/09/18 23:49

前提

Android StudioでGoogle AdMob Ads Activityプロジェクトを新規作成してビルドしてapkをインストールしました。

実現したいこと

とりあえずスケルトンアプリを起動したい。

発生している問題・エラーメッセージ

2022-09-19 08:38:38.239 10706-11020/com.example.xxxxxxx E/chromium: [ERROR:simple_file_enumerator.cc(21)] opendir /data/user/0/com.example.xxxxxxx/cache/WebView/Default/HTTP Cache/Code Cache/js: No such file or directory (2) 2022-09-19 08:38:38.240 10706-11020/com.example.xxxxxxx E/chromium: [ERROR:simple_index_file.cc(614)] Could not reconstruct index from disk

該当のソースコード

Kotlin

1package com.example.xxxxxxx 2 3import com.google.android.gms.ads.AdError 4import com.google.android.gms.ads.AdRequest 5import com.google.android.gms.ads.FullScreenContentCallback 6import com.google.android.gms.ads.LoadAdError 7import com.google.android.gms.ads.MobileAds 8import com.google.android.gms.ads.interstitial.InterstitialAd 9import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback 10import android.widget.Button 11import android.widget.TextView 12 13import android.os.Bundle 14import android.util.Log 15import androidx.appcompat.app.AppCompatActivity 16import android.view.Menu 17import android.view.MenuItem 18import android.widget.Toast 19import com.example.xxxxxxx.databinding.ActivityMainBinding 20 21import java.util.Locale 22 23// Remove the line below after defining your own ad unit ID. 24private const val TOAST_TEXT = "Test ads are being shown. " + 25 "To show live ads, replace the ad unit ID in res/values/strings.xml " + 26 "with your own ad unit ID." 27private const val START_LEVEL = 1 28 29class MainActivity : AppCompatActivity() { 30 31 private var currentLevel: Int = 0 32 private var interstitialAd: InterstitialAd? = null 33 private lateinit var nextLevelButton: Button 34 private lateinit var levelTextView: TextView 35 private val TAG = "MainActivity" 36 private lateinit var binding: ActivityMainBinding 37 38 override fun onCreate(savedInstanceState: Bundle?) { 39 super.onCreate(savedInstanceState) 40 41 binding = ActivityMainBinding.inflate(layoutInflater) 42 setContentView(binding.root) 43 44 MobileAds.initialize( 45 this 46 ) { } 47 // Load the InterstitialAd and set the adUnitId (defined in values/strings.xml). 48 loadInterstitialAd() 49 50 // Create the next level button, which tries to show an interstitial when clicked. 51 nextLevelButton = binding.nextLevelButton 52 nextLevelButton.isEnabled = false 53 nextLevelButton.setOnClickListener { showInterstitial() } 54 55 levelTextView = binding.level 56 // Create the text view to show the level number. 57 currentLevel = START_LEVEL 58 59 // Toasts the test ad message on the screen. Remove this after defining your own ad unit ID. 60 Toast.makeText(this, TOAST_TEXT, Toast.LENGTH_LONG).show() 61 } 62 63 override fun onCreateOptionsMenu(menu: Menu): Boolean { 64 // Inflate the menu; this adds items to the action bar if it is present. 65 menuInflater.inflate(R.menu.menu_main, menu) 66 return true 67 } 68 69 override fun onOptionsItemSelected(item: MenuItem) = 70 when (item.itemId) { 71 R.id.action_settings -> true 72 else -> super.onOptionsItemSelected(item) 73 } 74 75 private fun loadInterstitialAd() { 76 val adRequest = AdRequest.Builder().build() 77 InterstitialAd.load(this, getString(R.string.interstitial_ad_unit_id), adRequest, 78 object : InterstitialAdLoadCallback() { 79 override fun onAdLoaded(ad: InterstitialAd) { 80 // The interstitialAd reference will be null until 81 // an ad is loaded. 82 interstitialAd = ad 83 nextLevelButton.setEnabled(true) 84 Toast.makeText(this@MainActivity, "onAdLoaded()", Toast.LENGTH_SHORT) 85 .show() 86 ad.setFullScreenContentCallback( 87 object : FullScreenContentCallback() { 88 override fun onAdDismissedFullScreenContent() { 89 // Called when fullscreen content is dismissed. 90 // Make sure to set your reference to null so you don't 91 // show it a second time. 92 interstitialAd = null 93 Log.d(TAG, "The ad was dismissed.") 94 } 95 96 override fun onAdFailedToShowFullScreenContent(adError: AdError) { 97 // Called when fullscreen content failed to show. 98 // Make sure to set your reference to null so you don't 99 // show it a second time. 100 interstitialAd = null 101 Log.d(TAG, "The ad failed to show.") 102 } 103 104 override fun onAdShowedFullScreenContent() { 105 // Called when fullscreen content is shown. 106 Log.d(TAG, "The ad was shown.") 107 } 108 }) 109 } 110 111 override fun onAdFailedToLoad(loadAdError: LoadAdError) { 112 // Handle the error 113 Log.i(TAG, loadAdError.message) 114 interstitialAd = null 115 nextLevelButton.setEnabled(true) 116 val error: String = String.format( 117 Locale.ENGLISH, 118 "domain: %s, code: %d, message: %s", 119 loadAdError.domain, 120 loadAdError.code, 121 loadAdError.message 122 ) 123 Toast.makeText( 124 this@MainActivity, 125 "onAdFailedToLoad() with error: $error", Toast.LENGTH_SHORT 126 ) 127 .show() 128 } 129 }) 130 } 131 132 private fun showInterstitial() { 133 // Show the ad if it"s ready. Otherwise toast and reload the ad. 134 if (interstitialAd != null) { 135 interstitialAd!!.show(this) 136 } else { 137 Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show() 138 goToNextLevel() 139 } 140 } 141 142 private fun goToNextLevel() { 143 // Show the next level and reload the ad to prepare for the level after. 144 levelTextView.text = "Level " + (++currentLevel) 145 if (interstitialAd == null) { 146 loadInterstitialAd() 147 } 148 } 149}

試したこと

Android StudioでGoogle AdMob Ads Activityプロジェクトを新規作成してそのままビルドしてapkをインストールして実行してlogcatでエラーメッセージを拾いました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

AdMobのアカウントを作ってアプリIDを登録したら起動しました。

投稿2022/09/19 03:02

jmdajmw

総合スコア302

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問