java - 应用程序图标显示在广告中,但应用程序未运行
问题描述
我正在尝试创建启动画面。我可以在 ADB 移动屏幕上看到应用程序图标,但应用程序没有运行。附上 logcat
日志猫
2020-09-16 17:03:52.612 12836-12836/? I/.example.stree: Not late-enabling -Xcheck:jni (already on)
2020-09-16 17:03:52.639 12836-12836/? I/.example.stree: Unquickening 12 vdex files!
2020-09-16 17:03:52.641 12836-12836/? W/.example.stree: Unexpected CPU variant for X86 using defaults: x86
2020-09-16 17:03:52.850 12836-12836/com.example.street I/.example.stree: The ClassLoaderContext is a special shared library.
2020-09-16 17:03:53.056 12836-12836/com.example.street E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.street, PID: 12836
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.zzxw.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:27)
at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:3)
at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
... 10 more
2020-09-16 17:03:53.120 12836-12836/? I/Process: Sending signal. PID: 12836 SIG: 9
这是我的清单 xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.street">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的启动活动 xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context=".SplashActivity">
<ImageView
android:id="@+id/just_logo"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerInParent="true"
android:contentDescription="@string/app_name"
android:src="@drawable/just_logo" />
<TextView
android:layout_below="@id/just_logo"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_name"
android:textColor="@color/colorAccent"
android:textSize="32sp" />
</RelativeLayout>
主要活动文件
package com.example.street;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
飞溅活动文件
package com.example.street;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashActivity extends AppCompatActivity {
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_splashscreen);
handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},3000);
}
}
解决方案
1- 转到 AdMob > 应用程序 > 查看所有应用程序 > 搜索您的应用程序 >从他们的应用程序中复制APP ID
2 - 转到您的AndroidManifest.xml
文件,然后将以下行复制粘贴到 Application 标签内:
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="XXXXXXX"/>
3 - 将XXXXXXX替换为您的APP ID
推荐阅读
- r - 在 R 中闪亮加载页面一段固定的时间
- rabbitmq - rabbitmq中的vhost没有启动
- amazon-redshift - Redshift COPY 抛出错误,但“stl_load_errors”系统表未提供详细信息
- ios - 将 Firestore 数据分配给自定义对象
- python - 如何逐行获取groupby cumsum的总数
- dictionary - 如何在 Unity 中为类似我的世界的立方地形块的不同面应用不同的法线贴图纹理?
- c# - 如何在 .NET C# 应用程序 (WinForms) 中使用 ActiViz 时以 x64(64 位)平台为目标
- javascript - 当我在 html5 中按下按钮时,我正试图做出正确的移动
- linux - Web服务器中的Logrotation
- gnuradio - USRP N310 中 GNU Radio 中的 PSK 调制