LoginSignup
0
0

Unity版 Google AdMob トラブルシューター

Posted at

記事内容

Google AdMobが実装できなかった場合の解決策一覧

公式トラブルシューターを使う

広告がでるまで時間をまつ

正常に設定してあっても広告が配信されるまで時間がかかることも。最大1週間がかかることもあるらしい。

AppIdを更新。

Settingsから
image.png
AppIdを更新してから

image.png
ForceResolveを押さないとAppIDが更新されない
image.png
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上で勝手に置き換えるのでむやみに削除しないこと

image.png

gradleTemplate.properties
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**

launcherTemplate.gradle
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**

mainTemplate.gradle
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**

proguard-user.txt
### AdMob
-keep class com.google.unity.** {
   *;
}

-keep public class com.google.android.gms.ads.** {
    public *;
}

-keep public class com.google.ads.** {
    public *;
}

INCLUDESが消えていたことがあった。

settingsTemplate.gradle
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について

image.png
githhub上ではindex.htmlと同じ階層にあれば問題なし。

例えば登録したurlが

https://nextlabcross009.github.io/

だとすると

https://nextlabcross009.github.io/app-ads.txt

でapp-ads.txtにアクセスできれば正しく設定されている。
登録してから多く2日ほど認識するのに時間がかかる。それ以上の場合は設定方法を見直す。

googlePlayConsoleでは
デベロッパーページの
image.png
ウェブアドレスにgithubPagesのurlを設定する。
image.png

あとアカウント詳細の
image.png
ウェブサイトも変更する。
image.png

無事app-ads.txtが確認できると認証状況が準備完了となる
image.png
image.png

logcatで確認

UnityはAndroidのLogを表示するLogcatがある
image.png
Packagesからインスト。
これを使ってなんのエラーかを調べることができる。

java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener

androidビルドにはminifyというbuild時に最適化をかけて軽量化する機能がある。必要なクラスを削除しないように設定する。

まずminifyしているを確認。ProjectSettings>Player>Publishing Settings>Minify
image.png
画像ではRelease時に最適化をするという設定になっている。
なっている場合はadmobに必要なクラスは必要だと設定する必要がある。
Custom Proguard Fileにチェック
image.png

Pluginsにproguard-userが作成される
image.png
中身をコピペ

### AdMob
-keep class com.google.unity.** {
   *;
}

-keep public class com.google.android.gms.ads.** {
    public *;
}

-keep public class com.google.ads.** {
    public *;
}

これで完了

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0