在应用程序实例中尝试初始化我的应用程序中的admob sdk时遇到以下问题。当我们添加
android: name =".MyApplication"AndroidManifest.xml
Exception at,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
显示错误,因为您没有添加它。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 -->
请注意,永远不要在Application对象中存储可变的共享数据,因为这些数据随时可能消失或失效。相反,使用持久化策略(如file、SharedPreferences或SQLite)存储任何可变的共享数据。
https://guides.codepath.com/android/Understanding-the-Android-Application-Class
不应该在Application类中创建单例实例。