您的 android 清单中所需的元数据标记不存在。 MobileAds.initialize() 处的应用程序崩溃;

Posted

技术标签:

【中文标题】您的 android 清单中所需的元数据标记不存在。 MobileAds.initialize() 处的应用程序崩溃;【英文标题】:A required meta data tag in your android manifest does not exist. App crash at MobileAds.initialize(); 【发布时间】:2021-12-05 16:58:51 【问题描述】:

在我的应用程序实例中尝试初始化 admob sdk 时遇到以下问题。当我们添加时发生,

android:name=".MyApplication" 在 AndroidManifest.xml

MobileAds.initialize( this, new OnInitializationCompleteListener() @Override public void onInitializationComplete( @NonNull InitializationStatus initializationStatus) ); 例外

注意:如果我在活动级别初始化相同,则没有发现问题。

'W/System.err: com.google.android.gms.common.GooglePlayServicesMissingManifestValueException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />'

E/MetadataValueReader: This should never happen.
android.content.pm.PackageManager$NameNotFoundException: 
    at android.app.ApplicationPackageManager.getApplicationInfoAsUser(ApplicationPackageManager.java:461)
    at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:450)
    at com.google.android.gms.common.wrappers.PackageManagerWrapper.getApplicationInfo(com.google.android.gms:play-services-basement@@17.6.0:1)
    at com.google.android.gms.common.internal.zzaf.zzc(com.google.android.gms:play-services-basement@@17.6.0:4)
    at com.google.android.gms.common.internal.zzaf.zzb(com.google.android.gms:play-services-basement@@17.6.0:1)
    at com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(com.google.android.gms:play-services-basement@@17.6.0:7)
    at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(com.google.android.gms:play-services-basement@@17.6.0:2)
    at com.google.android.gms.internal.ads.zzcfz.zzn(com.google.android.gms:play-services-ads-lite@@20.4.0:2)
    at com.google.android.gms.internal.ads.zzbei.zzd(com.google.android.gms:play-services-ads-lite@@20.4.0:2)
    at com.google.android.gms.internal.ads.zzbhj.zzw(com.google.android.gms:play-services-ads-lite@@20.4.0:3)
    at com.google.android.gms.internal.ads.zzbhj.zzb(com.google.android.gms:play-services-ads-lite@@20.4.0:8)
    at com.google.android.gms.ads.MobileAds.initialize(com.google.android.gms:play-services-ads-lite@@20.4.0:3)
    at com.example.MyApplication.onCreate(MyApplication.java:31)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7249)
    at android.app.ActivityThread.access$1600(ActivityThread.java:294)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2168)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:264)
    at android.app.ActivityThread.main(ActivityThread.java:8245)
    at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
    2021-10-18 20:10:04.690 27613-27640/com.example E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1

Process: com.example, PID: 27613
java.lang.SecurityException: Permission Denial: getIntentSender() from pid=27613, uid=11251, (need uid=-1) is not allowed to send as package 
    at android.os.Parcel.createExceptionOrNull(Parcel.java:2389)
    at android.os.Parcel.createException(Parcel.java:2373)
    at android.os.Parcel.readException(Parcel.java:2356)
    at android.os.Parcel.readException(Parcel.java:2298)
    at android.app.IActivityManager$Stub$Proxy.getIntentSenderWithFeature(IActivityManager.java:6832)
    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:584)
    at android.app.PendingIntent.getBroadcast(PendingIntent.java:567)
    at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
    at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
    at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)
2021-10-18 20:10:05.895 27661-27661/? E/weather.servic: Unknown bits set in runtime_flags: 0x40000000
2021-10-18 20:10:05.900 27661-27661/? E/weather.servic: Not starting debugger since process cannot load the jdwp agent.
2021-10-18 20:10:05.910 27661-27661/? E/RefClass: java.lang.reflect.InvocationTargetException

【问题讨论】:

【参考方案1】:

它给出了一个错误,因为你没有添加它。 AdmobQuickStart这个链接可以获取详细安装信息。

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

【讨论】:

它已经在那里了,兄弟。但仍然出现此错误。 如果你分享清单文件,我想我们可以解决问题。 只有当我们在应用程序类中初始化 sdk 并在清单文件中引用它时才会出现此错误,但如果我们在活动中执行它就可以正常工作。【参考方案2】:

请注意,您永远不应将可变共享数据存储在 Application 对象中,因为这些数据可能随时消失或变为无效。相反,使用持久性策略(例如文件、SharedPreferences 或 SQLite)存储任何可变的共享数据。

https://guides.codepath.com/android/Understanding-the-Android-Application-Class

不应在 Application 类中创建单例实例。

【讨论】:

package="com.example"&gt; this 由于包名,它给出了一个错误。示例不允许在包名中使用它。com.kirandani 请试试这个。 我已将包名修改为“example”。这不是真的。 MobileAds.initialize( this, new OnInitializationCompleteListener() @Override public void onInitializationComplete( @NonNull InitializationStatus initializationStatus) ); 你在哪里调用这个命令?我的应用程序在 ? 是的,在 myApplication 类的 oncreate 中,如 admob App Open Ads sdk 的文档中所建议的那样 我不知道问题可能出在 MyApplication.class

以上是关于您的 android 清单中所需的元数据标记不存在。 MobileAds.initialize() 处的应用程序崩溃;的主要内容,如果未能解决你的问题,请参考以下文章

清单的应用程序标记中缺少名称为“com.google.android.gms.appstate.APP_ID”的元数据标记

Android 11 应用程序崩溃并显示“您的应用程序的 AndroidManifest.xml 中的元数据标记没有正确的值。预期为 12451000,但发现为 4323000”

如何从另一个表中获取数据并插入到 EF Core 中所需的表中

(GCS) 查看此对象的元数据所需的其他权限:请求对象所有者授予您“storage.objects.get”权限

如何去计算hdfs中namenode中所需的堆内存大小

从 web api 加载谷歌地图所需的标记,并在相机移动时动态加载其他标记