While you can use ad inspector to inspect ad behavior during development, testing, and troubleshooting, the tool might increase memory usage when enabled. You might want to disable ad inspector during performance profiling and memory checking. This feature makes sure that ad inspector doesn't run and interfere with your app's performance measurements.
Disabling ad inspector prevents the tool from increasing memory usage or launching through gestures, the debug menu, or method calls. You can disable ad inspector while performance testing in test mode. In production, ad inspector is always disabled and doesn't impact your app's performance.
В этом руководстве рассматривается отключение инспектора рекламы и проверка правильности его отключения.
Предварительные требования
Прежде чем продолжить, выполните следующие действия:
- Настройте GMA Next-Gen SDK .
- Используйте GMA Next-Gen SDK версии 1.3.0 или выше.
Отключить при выборе типа сборки
To keep ad inspector available in debug builds while disabling the tool in profiling builds, manage the build configuration setting by using Gradle build types and manifest placeholders. Complete the following steps:
Определите свойства
manifestPlaceholdersв файле сборки Gradle.Assign values for each build type. The following example defines the key
disableAdInspector, creates aprofilebuild type that inherits from thereleasebuild type. This example also sets the key value totruefor profile builds and afalsevalue for debug and release builds.Котлин
android { buildTypes { getByName("debug") { manifestPlaceholders["disableAdInspector"] = "false" } getByName("release") { optimization { enable = false } manifestPlaceholders["disableAdInspector"] = "false" } create("profile") { initWith(getByName("release")) manifestPlaceholders["disableAdInspector"] = "true" } } }
Классный
android { buildTypes { release { manifestPlaceholders = [disableAdInspector: "false"] } debug { manifestPlaceholders = [disableAdInspector: "false"] } create("profile") { initWith(getByName("release")) manifestPlaceholders = [disableAdInspector: "true"] } } }
Укажите ссылку на переменную-заполнитель в файле манифеста вашего приложения. В следующем примере используется переменная-заполнитель
disableAdInspector, которую вы определили на предыдущем шаге.<application> <!-- Dynamically enable or disable ad inspector based on build type --> <meta-data android:name= "com.google.android.libraries.ads.mobile.sdk.flag.DISABLE_AD_INSPECTOR" android:value="${disableAdInspector}" /> </application>
Проверьте отключение
При попытке открыть инспектор рекламы, если он отключен в файле AndroidManifest.xml , в Logcat появится следующее сообщение:
Ad inspector is disabled in the AndroidManifest.xml.
Вызов метода MobileAds.openAdInspector возвращает объект AdInspectorError в функции обратного вызова, уведомляя приложение о том, что инспектор рекламы не может быть открыт:
Ad inspector cannot be opened because it is disabled in the AndroidManifest.xml.