尝试在Android应用程序中实施AdMob时收到“无效的应用程序ID”错误

时间:2018-11-23 19:20:52

标签: java android admob

我已经关注了Google admob vidoes 3天了,但是在logCat中却遇到了运行时错误:

  

Logcat

     

进程:com.exafmpflle.android.happybirthdayyyy,PID:19319      java.lang.RuntimeException:无法获取提供程序      com.google.android.gms.ads.MobileAdsInitProvider:      java.lang.IllegalStateException:        无效的应用程序ID。请按照以下说明操作:*           *找到您的应用ID。

活动主体

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:background="@drawable/january_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.exafmpflle.android.xxxxxxx.MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/idbuttonfirst"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/idbuttonsecond"
        android:layout_marginStart="79dp"
        android:background="@drawable/ic_iconaphoto"
        android:src="?attr/selectableItemBackground" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-52924220005747xx/xxxxxxxx"  />


</RelativeLayout>
<android.support.design.widget.NavigationView
    android:layout_gravity="start"
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu" />

AndroidMainfest
allso is in my Mainfest

<manifest 
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exafmpflle.android.xxxxxxx"
android:installLocation="auto">

<!-- Include required 2 permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature android:name="android.permission.CALL_PHONE" 
android:required="false" />
<uses-feature android:name="android.permission.READ_PHONE_STATE" 
android:required="false" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

<application
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:installLocation="auto"
    android:icon="@mipmap/ic_launcher_birthdaycake"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

    <!--This meta-data tag is required to use Google Play Services.-->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <!-- Sample AdMob App ID: ca-app-pub-5292422000574799~xxxxxxxx -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="[ca-app-pub-5292422000574799~xxxxxxxxxx"/>

    <activity
        android:name=".SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--Include the AdActivity configChanges and theme. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:theme="@android:style/Theme.Translucent" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:noHistory="false"/>

    <activity
        android:label="@string/about"
        android:name=".About"
        android:screenOrientation="portrait"
        android:noHistory="false" />

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />

    <!-- [START firebase_service] -->

    <service
        android:name=".FirebaseMessagingService" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <meta-data

    android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorPrimary" />

   <!-- FirebaseMessagingService performs security checks at runtime,
         no need for explicit permissions despite exported="true" -->
    <service

    android:name="com.google.firebase.messaging.FirebaseMessagingService"
        android:exported="true" >
        <intent-filter
            android:priority="-500" >
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
        android:enabled="true"
        android:exported="false" >
    </receiver>
    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.INSTALL_PACKAGES" >
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.google.android.gms.measurement.AppMeasurementService"
        android:enabled="true"
        android:exported="false" />
    <service
    android:name="com.google.android.gms.measurement.AppMeasurementJobService"  
        android:enabled="true"
        android:exported="false"
        android:permission="android.permission.BIND_JOB_SERVICE" />

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.exafmpflle.android.happybirthdayyyy" />
        </intent-filter>
    </receiver>

    <!-- FirebaseInstanceIdService performs security checks at runtime,
         no need for explicit permissions despite exported="true" -->
    <service
        android:name="com.google.firebase.iid.FirebaseInstanceIdService"
        android:exported="true" >
        <intent-filter android:priority="-500" >
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="com.exafmpflle.xxxxxx.xxxxxxxxx.firebaseinitprovider"
        android:exported="false"
        android:initOrder="100" />


</application>

1 个答案:

答案 0 :(得分:1)

在清单文件中

<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="[ca-app-pub-5292422000574799~xxxxxxxxxx"/>

将其更改为:

<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-5292422000574799~xxxxxxxxxx"/>

卸下左方括号。 为了更好的实践,请在string.xml文件中定义此类ID,而不是直接使用。