当我将广告实现添加到 Build.Gradle 时,我的应用程序自动关闭

问题描述 投票:0回答:1

我的应用程序可以运行。然后我将一行添加到我的

build.gradle
(即 admob 广告)中:

implementation 'com.google.android.gms:play-services-ads:22.5.0'

然后我的应用程序将无法工作,加载后会自动关闭。

我的手机是Android Nougat 7.0(即sdk 24.0)。据我所知,广告应该没问题。我说得对吗?

知道为什么会失败吗?

编辑:

错误是(抱歉,格式不太好,请向右滚动):

E  FATAL EXCEPTION: main
                                                                                                    Process: com.myapp.www.myapp, PID: 6415
                                                                                                    java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
                                                                                                    
                                                                                                    ******************************************************************************
                                                                                                    * Invalid application ID. Follow instructions here:                          *
                                                                                                    * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
                                                                                                    * to find your app ID.                                                       *
                                                                                                    * Google Ad Manager publishers should follow instructions here:              *
                                                                                                    * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
                                                                                                    ******************************************************************************
                                                                                                    
                                                                                                    
                                                                                                        at android.app.ActivityThread.installProvider(ActivityThread.java:5977)
                                                                                                        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5545)
                                                                                                        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5484)
                                                                                                        at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                                        at android.os.Looper.loop(Looper.java:203)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6251)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1067)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
                                                                                                    Caused by: java.lang.IllegalStateException: 
                                                                                                    
                                                                                                    ******************************************************************************
                                                                                                    * Invalid application ID. Follow instructions here:                          *
                                                                                                    * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
                                                                                                    * to find your app ID.                                                       *
                                                                                                    * Google Ad Manager publishers should follow instructions here:              *
                                                                                                    * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
                                                                                                    ******************************************************************************
                                                                                                    
                                                                                                    
                                                                                                        at com.google.android.gms.ads.internal.client.zzek.attachInfo(com.google.android.gms:play-services-ads-lite@@22.5.0:15)
                                                                                                        at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@22.5.0:1)
                                                                                                        at android.app.ActivityThread.installProvider(ActivityThread.java:5974)
                                                                                                        ... 10 more

我的项目

build.gradle
是(注意我必须哈希出
allprojects
,否则gradle将不会同步):

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}

//allprojects {
//    repositories {
//        google()
//        mavenCentral()
//    }
//}

我的 Android 清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.myapp.www.myapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" />

    <!--        android:dataExtractionRules="@xml/data_extraction_rules"-->
    <!--        android:fullBackupContent="@xml/backup_rules"-->
    <!--        tools:targetApi="33"-->
    <!--        tools:ignore="ExtraText">-->


<!--    <meta-data-->
<!--        android:name="android.app.lib_name"-->
<!--        android:value="" />-->


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_foreground"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round_foreground"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApp">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|screenSize"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

我的应用程序

build.gradle

plugins {
    id 'com.android.application'
}

android {
    compileSdk 34

    defaultConfig {
        applicationId "com.myapp.www.myapp"
        minSdk 19
        targetSdk 34
        versionCode 1021
        versionName "1.021"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

        javaCompileOptions {
            gradle.projectsEvaluated {
                tasks.withType(JavaCompile) {
                    options.compilerArgs << "-Xlint:deprecation"
                }
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    def billing_version = "6.0.1"
    /* This is for the billing library we are using */
    /* implementation 'com.anjlab.android.iab.v3:library:1.0.44' */
    /* New Google's Billing */
    /* implementation 'com.android.billingclient:billing:2.2.0' */
    implementation "com.android.billingclient:billing:$billing_version"

    /* TEMP ADVERTS */
    /* This is for adverts */
    /* implementation 'com.google.android.gms:play-services-ads:15.0.0' */
    /* Consent for Adverts GDPR */
    /* /* implementation 'com.google.android.ads.consent:consent-library:1.0.6' */
    /* implementation 'com.google.android.ads.consent:consent-library:1.0.7' */

    /* Adverts */
    implementation 'com.google.android.gms:play-services-ads:22.5.0'
    /* GDPR */
    /* implementation 'com.google.android.ump:user-messaging-platform:2.1.0' */

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    /* This for ImmutableList */
    implementation 'com.google.guava:guava:31.1-android'
    implementation 'androidx.multidex:multidex:2.0.1'
}

在我的

onCreate
功能中:

    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });
android admob android-7.0-nougat
1个回答
0
投票

错误日志:

******************************************************************************
* Invalid application ID. Follow instructions here:                          *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to find your app ID.                                                       *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

您应该提供一个有效的 ID 才能启动。从 Ad Manager 网页界面查找您的应用 ID。此外,您还可以使用示例 ID 来测试 SDK。如果您尝试使用此 ID,应用程序将打开。

您必须将此部分替换为您自己的id。

android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"

带有样品ID:

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-3940256099942544~3347511713"/>
© www.soinside.com 2019 - 2024. All rights reserved.