首页 > 解决方案 > 实施 com.google.android.gms:play-services-ads:20.1.0 后我的应用程序崩溃

问题描述

我有问题,当我实施时

实施 'com.google.android.gms:play-services-ads:20.1.0'

该应用程序不会开始显示消息“继续停止”

在此处输入图像描述

构建.gradle

allprojects {
    repositories {
        google()
    }
}



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0-alpha04'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.squareup.okhttp3:okhttp:3.9.1'
    //noinspection GradleDependency
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:20.1.0'

}

如果我删除“com.google.android.gms:play-services-ads:20.1.0”行或更改为较低版本我收到错误初始化未解决或广告未解决

com.google.android.gms。广告初始化.InitializationStatus;

在 AndroidManifest.xml 我添加了

<meta-data
            android:name="ca-app-__________________~______________"
            android:value="ca-app-pub-138__________/_____________"/>

我尝试了我在这里找到的这个解决方案,也有同样的问题

<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

主.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/linear2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:orientation="horizontal">
            <LinearLayout
                android:id="@+id/linear3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="8dp"
                android:gravity="center_vertical"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/textview1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:text="اكواد جافا"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:textColor="#FFFF00" />
                <LinearLayout
                    android:id="@+id/linear4"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:padding="8dp"
                    android:orientation="vertical"
                    android:layout_weight="1" />
                <ImageView
                    android:id="@+id/imageview2"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:src="@drawable/ic_close_black"
                    android:scaleType="fitXY" />
                <EditText
                    android:id="@+id/edittext1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:textSize="12sp"
                    android:textColor="#000000"
                    android:hint="اكتب هنا للبحث"
                    android:textColorHint="#607D8B"
                    android:layout_weight="1" />
                <ImageView
                    android:id="@+id/imageview1"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:src="@drawable/search"
                    android:scaleType="fitXY" />
            </LinearLayout>
        </LinearLayout>

        <ListView
            android:id="@+id/listview1"
            android:layout_width="match_parent"
            android:layout_height="595dp"
            android:choiceMode="none"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:padding="8dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                app:adSize="BANNER"
                app:adUnitId="ca-app-pub-39__256__94__44/630__78___" />

        </LinearLayout>
    </LinearLayout>
</LinearLayout>

以及我在与 Android 开发人员网站共享的相同代码中使用的代码 java 我的 ID 都很好...等

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
         
        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });
         
        adView = (AdView) findViewById(R.id.adView);
        
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
      

    }
}

当我打开我的应用程序时,它会崩溃......任何解决方案!?

这是日志:

2021-05-02 15:11:57.254 23325-23325/? I/ube.hichem.sof: Not late-enabling -Xcheck:jni (already on)
2021-05-02 15:11:57.282 23325-23325/? I/ube.hichem.sof: Unquickening 12 vdex files!
2021-05-02 15:11:57.284 23325-23325/? W/ube.hichem.sof: Unexpected CPU variant for X86 using defaults: x86
2021-05-02 15:11:57.758 23325-23325/blocks.youtube.hichem.soft D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
2021-05-02 15:11:57.760 23325-23325/blocks.youtube.hichem.soft I/ube.hichem.sof: The ClassLoaderContext is a special shared library.
2021-05-02 15:11:59.213 23325-23325/blocks.youtube.hichem.soft D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-05-02 15:11:59.214 23325-23325/blocks.youtube.hichem.soft D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-05-02 15:11:59.225 23325-23325/blocks.youtube.hichem.soft D/AndroidRuntime: Shutting down VM
2021-05-02 15:11:59.227 23325-23325/blocks.youtube.hichem.soft E/AndroidRuntime: FATAL EXCEPTION: main
    Process: blocks.youtube.hichem.soft, PID: 23325
    java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
    
    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here:                                       *
    * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
    * to add a valid App ID inside the AndroidManifest.                          *
    * Google Ad Manager publishers should follow instructions here:              *
    * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
    ******************************************************************************
    
    
        at android.app.ActivityThread.installProvider(ActivityThread.java:7244)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.IllegalStateException: 
    
    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here:                                       *
    * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
    * to add a valid App ID inside the AndroidManifest.                          *
    * Google Ad Manager publishers should follow instructions here:              *
    * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
    ******************************************************************************
    
    
        at com.google.android.gms.internal.ads.zzacz.attachInfo(com.google.android.gms:play-services-ads-lite@@20.1.0:20)
        at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@20.1.0:1)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
            ... 10 more
2021-05-02 15:11:59.295 23325-23325/blocks.youtube.hichem.soft I/Process: Sending signal. PID: 23325 SIG: 9

标签: javaandroid

解决方案


经过长时间的尝试,我发现我得到的错误是因为我的小错误。

我想逐步与您分享解决方案,希望对某人有所帮助:

该应用程序崩溃了,因为您将“广告” id 代替了“应用程序” id,首先从 google Admob 带来您的“应用程序 id”:

在此处输入图像描述

在这里你会得到一个像这样的窗口

在此处输入图像描述

复制你的 App id

然后转到您的 AndroidManifest 文件并通过 Bellow 元数据

注意:第一行 APPLICATION_ID 保持原样

在您的 APP ID 后面的第二行中

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

如果您执行此步骤,您的应用程序将毫无问题地启动

祝你好运


推荐阅读