記事内容
Google AdMobが実装できなかった場合の解決策一覧
公式トラブルシューターを使う
広告がでるまで時間をまつ
正常に設定してあっても広告が配信されるまで時間がかかることも。最大1週間がかかることもあるらしい。
AppIdを更新。
ForceResolveを押さないとAppIDが更新されない
AndroidManifedt.xmlはUnity上に認識されないので以下のパスからAPPIdが正しく設定されているいかを確認しよう。
Assets\Plugins\Android\GoogleMobileAdsPlugin.androidlib\AndroidManifest.xml
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~1458002511" />
build.gradle
あまり詳しくないので、参考になるように私の設定をのせる
**HOGEHOGE**
はUnity上で勝手に置き換えるのでむやみに削除しないこと
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
unityStreamingAssets=**STREAMING_ASSETS**
# Android Resolver Properties Start
android.useAndroidX=true
android.enableJetifier=true
# Android Resolver Properties End
**ADDITIONAL_PROPERTIES**
apply plugin: 'com.android.application'
dependencies {
implementation project(':unityLibrary')
}
android {
ndkPath "**NDKPATH**"
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
aaptOptions {
noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
}**SIGN**
lintOptions {
abortOnError false
}
buildTypes {
debug {
minifyEnabled **MINIFY_DEBUG**
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
jniDebuggable true
}
release {
minifyEnabled **MINIFY_RELEASE**
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
}
}**PACKAGING_OPTIONS****PLAY_ASSET_PACKS****SPLITS**
**BUILT_APK_LOCATION**
bundle {
language {
enableSplit = false
}
density {
enableSplit = false
}
abi {
enableSplit = true
}
}
}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**
apply plugin: 'com.android.library'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12
implementation 'com.google.android.gms:play-services-ads:23.0.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
implementation 'com.google.android.gms:play-services-games:9.8.0' // Assets/Editor/Dependencies.xml:41
implementation 'com.google.android.ump:user-messaging-platform:2.2.0' // Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7
// Android Resolver Dependencies End
**DEPS**}
// Android Resolver Exclusions Start
android {
packagingOptions {
exclude ('/lib/armeabi/*' + '*')
exclude ('/lib/armeabi-v7a/*' + '*')
exclude ('/lib/mips/*' + '*')
exclude ('/lib/mips64/*' + '*')
exclude ('/lib/x86/*' + '*')
exclude ('/lib/x86_64/*' + '*')
}
}
// Android Resolver Exclusions End
android {
ndkPath "**NDKPATH**"
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
}**PACKAGING_OPTIONS**
}
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**
### AdMob
-keep class com.google.unity.** {
*;
}
-keep public class com.google.android.gms.ads.** {
public *;
}
-keep public class com.google.ads.** {
public *;
}
INCLUDESが消えていたことがあった。
pluginManagement {
repositories {
**ARTIFACTORYREPOSITORY**
gradlePluginPortal()
google()
mavenCentral()
}
}
include ':launcher', ':unityLibrary'
**INCLUDES**
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
**ARTIFACTORYREPOSITORY**
google()
mavenCentral()
// Android Resolver Repos Start
def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
maven {
url "https://repo.maven.apache.org/maven2" // Assets/Editor/Dependencies.xml:12
}
maven {
url "https://maven.google.com" // Assets/Editor/Dependencies.xml:41
}
maven {
url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7
}
mavenLocal()
// Android Resolver Repos End
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
app-ads.txtについて
githhub上ではindex.htmlと同じ階層にあれば問題なし。
例えば登録したurlが
https://nextlabcross009.github.io/
だとすると
https://nextlabcross009.github.io/app-ads.txt
でapp-ads.txtにアクセスできれば正しく設定されている。
登録してから多く2日ほど認識するのに時間がかかる。それ以上の場合は設定方法を見直す。
googlePlayConsoleでは
デベロッパーページの
ウェブアドレスにgithubPagesのurlを設定する。
無事app-ads.txtが確認できると認証状況が準備完了となる
logcatで確認
UnityはAndroidのLogを表示するLogcatがある
Packagesからインスト。
これを使ってなんのエラーかを調べることができる。
java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener
androidビルドにはminifyというbuild時に最適化をかけて軽量化する機能がある。必要なクラスを削除しないように設定する。
まずminifyしているを確認。ProjectSettings>Player>Publishing Settings>Minify
画像ではRelease時に最適化をするという設定になっている。
なっている場合はadmobに必要なクラスは必要だと設定する必要がある。
Custom Proguard Fileにチェック
Pluginsにproguard-userが作成される
中身をコピペ
### AdMob
-keep class com.google.unity.** {
*;
}
-keep public class com.google.android.gms.ads.** {
public *;
}
-keep public class com.google.ads.** {
public *;
}
これで完了
参考サイト