ゆくゆくはアプリに広告を掲載したいと考えていますが、うまくいきません。
試しに作成したプロジェクトでいきなりつまづいています。
MainActivityで「シンボルgmsを解決できません」のエラーが表示されまったく動きません。
試しにandroidstudioでプロジェクトADMobTestを作成しました。
Android Studioのバージョンは、Android Studio 4.2.1
compileSdkVersion:31
minSdkVersion:16
にしています。
Google AdMobのスタートガイド
https://developers.google.com/admob/android/quick-start?hl=ja
の手順に沿って、進めています。
①初めにbuild.gradle(プロジェクト:ADMobTest)を下記のようにしました。
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:4.2.1" } } allprojects { repositories { google() mavenCentral() // jcenter() // Warning: this repository is going to shut down soon } } task clean(type: Delete) { delete rootProject.buildDir }
②次に
build.gradle(モジュール:ADMobTest.app)のdependenciesに追記し、下記のようになりました。
dependencies { implementation 'com.google.android.gms:play-services-ads:20.6.0' implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'com.google.android.gms:play-services-ads:20.6.0' }
③最期に
アプリの AndroidManifest.xml ファイルに AdMob アプリ ID(AdMob 管理画面で識別される)を追加しました。
IDはテスト広告用です。
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.websarva.wings.android.admobtest"> <uses-sdk android:minSdkVersion="16" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AdMobTest"> <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544/1033173712"/> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
④そのうえで、MainActivityにガイド通りのコードを記述しても、
import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
gmsの文字が赤く表示され、「シンボルgmsを解決できません」となります。
そもそも根本的な何かを間違えいるような気もしますが、それが何か全く分かりません。
一体何が悪いのか、どなたかわかりますでしょうか。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。