【问题标题】:How to add the correct admob or adview dependency to an Android app如何将正确的 admob 或 adview 依赖项添加到 Android 应用程序
【发布时间】:2020-05-23 05:46:25
【问题描述】:

我正在开发一个应用程序,我想在其中添加一个 admob 横幅。我询问了清单文件中 Internet 和网络状态的权限。然后我添加了admob的依赖。进入gradle文件的依赖后,我手机app中的app在测试时崩溃了。

当我添加依赖项时会发生这种情况。如果由于其他原因发生这种情况,我想找到正确的依赖关系或一些如何解决此问题。

这是我添加的依赖项:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.3.0'
}

【问题讨论】:

  • 需要更多细节。可以分享一下错误跟踪日志吗?

标签: android android-studio dependencies admob


【解决方案1】:

您需要在 Manifest

中的 Aplication 内部添加以下 Meta 标签
 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

    //Add this
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="@string/admob_app_id" /> //Add here your admob app id

    ...

</application>

希望对你有帮助!

谢谢。

【讨论】:

    【解决方案2】:

    我认为您需要在应用程序的清单 xml 中添加 2 个元数据标签。

    <application>
    
    <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="@string/admob_app_id" /> // put your admob app id in quotes
    
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
    </application>
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-01
      • 2011-11-11
      • 2011-12-02
      • 2019-11-09
      • 2015-08-11
      • 2021-06-05
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多