The MapsInitializer.initialize method forces you to be called on main thread, and yet it causes ANRs.
ANR:
ii: Application Not Responding for at least 5000 ms.
at android.os.BinderProxy.transactNative(Binder.java)
at android.os.BinderProxy.transact(Binder.java:511)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:644)
at android.content.ContentResolver.call(ContentResolver.java:1447)
at com.google.maps.api.android.lib6.drd.o.A(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:41)
at com.google.maps.api.android.lib6.impl.ay.a(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:8)
at fjj.a(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:1)
at com.google.android.gms.maps.internal.CreatorImpl.c(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:35)
at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:1)
at com.google.android.gms.maps.internal.i.bo(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:5)
at baw.onTransact(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200031.477283333.477283333:4)
at android.os.Binder.transact(Binder.java:392)
at js8.A(com.google.android.gms:play-services-maps##18.1.0:8)
at h49.N0(com.google.android.gms:play-services-maps##18.1.0:13)
at q84.a(com.google.android.gms:play-services-maps##18.1.0:99)
Running on non main thread:
java.lang.IllegalStateException: Method addObserver must be called on the main thread
at xy.j(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:0)
at xy.b(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:1)
at com.google.android.libraries.geo.crash.monitoring.UncleanTerminationDetector.i(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:6)
at com.google.android.gms.maps.internal.CreatorImpl.c(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:53)
at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:1)
at com.google.android.gms.maps.internal.i.bm(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:5)
at ayk.onTransact(:com.google.android.gms.policy_maps_core_dynamite#223812200#223812200065.477283333.477283333:4)
at android.os.Binder.transact(Binder.java:1164)
at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps##18.1.0:2)
at com.google.android.gms.maps.internal.zze.zzl(com.google.android.gms:play-services-maps##18.1.0:4)
at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps##18.1.0:12)
Related
I have a form that I open in a webview in my app, after I complete it, it will appear a button that will let me download a pdf andd open it but when I do this I keep getting the next error:
OneSignal: FusedLocationApi.requestLocationUpdates failed!
java.lang.NullPointerException: Calling thread must be a prepared Looper thread.
at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement##17.6.0:2)
at com.google.android.gms.internal.location.zzz.requestLocationUpdates(com.google.android.gms:play-services-location##18.0.0:4)
at com.onesignal.GMSLocationController$FusedLocationApiWrapper.requestLocationUpdates(GMSLocationController.java:198)
at com.onesignal.GMSLocationController$LocationUpdateListener.init(GMSLocationController.java:181)
at com.onesignal.GMSLocationController$LocationUpdateListener.<init>(GMSLocationController.java:165)
at com.onesignal.GMSLocationController.onFocusChange(GMSLocationController.java:117)
at com.onesignal.LocationController.onFocusChange(LocationController.java:326)
at com.onesignal.OneSignal.onAppLostFocus(OneSignal.java:1308)
at com.onesignal.ActivityLifecycleHandler$AppFocusRunnable.run(ActivityLifecycleHandler.java:279)
at java.lang.Thread.run(Thread.java:923)
The button will appear in the webview. I think I get that error because I open the pdf on the main thread.
Recently i see a quite significant increase of ANRs in the Google Play Console for my app. There are reports for different types of causes but they have one thing in common:
Both the main thread and my worker thread are blocked and at least one of them is always blocked while accessing a method from "android.app.ResourcesManager"
Example 1:
"main" prio=5 tid=1 Blocked
at android.app.ResourcesManager.getAdjustedDisplay (ResourcesManager.java:353)
at android.app.ContextImpl.getDisplayNoVerify (ContextImpl.java:2559)
at android.view.WindowManagerImpl.getDefaultDisplay (WindowManagerImpl.java:164)
at org.n277.lynxlauncher.helper.DeviceUtilities.updateSystemHelper (DeviceUtilities.java:225)
at org.n277.lynxlauncher.views.DragContainerFrameLayout.onApplyWindowInsets (DragContainerFrameLayout.java:231)
at android.view.View.dispatchApplyWindowInsets (View.java:11399)
at android.view.ViewGroup.dispatchApplyWindowInsets (ViewGroup.java:7393)
at android.view.ViewGroup.newDispatchApplyWindowInsets (ViewGroup.java:7418)
at android.view.ViewGroup.dispatchApplyWindowInsets (ViewGroup.java:7400)
at android.view.ViewGroup.newDispatchApplyWindowInsets (ViewGroup.java:7418)
...
"Lynx-Worker" prio=5 tid=17 Blocked
at android.app.ResourcesManager.getOrCreateResources (ResourcesManager.java:865)
at android.app.ResourcesManager.getResources (ResourcesManager.java:982)
at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2411)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:1527)
at android.app.ApplicationPackageManager.getDrawable (ApplicationPackageManager.java:1277)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2684)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2655)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:516)
at android.content.pm.ComponentInfo.loadDefaultIcon (ComponentInfo.java:256)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2687)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2655)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:516)
at android.content.pm.LauncherActivityInfo.getIcon (LauncherActivityInfo.java:117)
at org.n277.lynxlauncher.visual.c.d.v (SourceFile:1)
at org.n277.lynxlauncher.visual.c.d.u (SourceFile:3)
...
The main thread tries to get the display size for measurement using the "windowManager.getDefaultDisplay().getSize()" method (for Pre Android R devices). The worker thread tries to get the Icon of an Application using a LauncherActivityInfo.
Example 2:
"main" prio=5 tid=1 Blocked
at android.view.WindowManagerImpl.getCurrentBounds (WindowManagerImpl.java:241)
at android.view.WindowManagerImpl.getCurrentWindowMetrics (WindowManagerImpl.java:235)
at org.n277.lynxlauncher.helper.DeviceUtilities.getUsableHeight (DeviceUtilities.java:190)
at org.n277.lynxlauncher.views.FullScreenFrameLayout.onMeasure (FullScreenFrameLayout.java:114)
at android.view.View.measure (View.java:25532)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
at android.view.View.measure (View.java:25532)
at android.widget.RelativeLayout.measureChildHorizontal (RelativeLayout.java:735)
...
"Lynx-Worker" prio=5 tid=17 Blocked
at android.app.ResourcesManager.createResources (ResourcesManager.java:846)
at android.app.ResourcesManager.getResources (ResourcesManager.java:947)
at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2296)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:1672)
at android.app.ApplicationPackageManager.getDrawable (ApplicationPackageManager.java:1437)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2950)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon (ApplicationPackageManager.java:2953)
at android.app.ApplicationPackageManager.loadItemIcon (ApplicationPackageManager.java:2929)
at android.content.pm.PackageItemInfo.loadIcon (PackageItemInfo.java:271)
at android.content.pm.LauncherActivityInfo.getIcon (LauncherActivityInfo.java:119)
at org.n277.lynxlauncher.visual.c.d.v (SourceFile:1)
at org.n277.lynxlauncher.visual.c.d.u (SourceFile:3)
...
Again, the main thread tries to get the display size for measurement, but this time using windowManager.getCurrentWindowMetrics(). The worker thread again tries to get the Icon of an Application using a LauncherActivityInfo.
Example 3:
Exactly the same as example 2, but there is another generic thread stuck with the very same trace as the worker thread.
For me it really looks like there is some sort of deadlock when accessing the "android.app.ResourcesManager" class from multuple threads.
I suspect that also "WindowManagerImpl.getCurrentBounds" is accessing the ResourcesManager although it is not shown explicidly. However, this did not happen before the last update and i have not changed anything regarding the threading. The only thing that comes into my mind is that i updated several dependencies:
buildToolsVersion from 30.0.0 to 30.0.2
com.android.billingclient:billing from 3.0.3 to 4.0.0
androidx.appcompat:appcompat from 1.2.0 to 1.3.0
androidx.recyclerview:recyclerview from 1.1.0 to 1.2.1
What i suspect is thas it is causing problems now when the Resources are accessed from multiple threads simultaneously. Moving the App Icon loading into the main thread however does not seem wise to me as this would clog this thread easily. For the "LauncherActivityInfo.getIcon" method it is clear that it has to access the resources to get the icon of the app (although not the resources of the app the method is called from but from the app from which the icon should be loaded). However many other tasks are also performed in the worker thread and many of the called API methods could also access the resources internally even though it is not obvious.
Has anyone else experiencef problems of this kind? (after an update of one of the above mentioned dependencies).
Or has anyone found a workaround/solution to this specific ANR?
My application gives ANR popup. To find out the reason I have generated a sample.trace file using this line:
Debug.startMethodTracing("sample");
in onCreate method of my activity, and I have added this line to stop tracing to the onDestroy method of the activity:
Debug.stopMethodTracing();
I get the sample.trace file after I destroy the activity. But when I review the file I do not understand it. As I learn there is an online tool which is Perfetto.
However when I open the file in there, it shows blank page while I am expecting some UI.
As a result I need to understand the file and find out the problems that cause the ANR issue but I do not know how to do.
This is a piece of my sample.trace file :
*version
3
data-file-overflow=true
clock=dual
elapsed-time-usec=165959496
num-method-calls=599184
clock-call-overhead-nsec=3338
vm=art
pid=13695
*threads
14436 RxIoScheduler-2
14460 Okio Watchdog
14589 AsyncTask #5
14612 Timer-0
15013 AsyncTask #6
15014 AsyncTask #7
15015 AsyncTask #8
15049 Timer-4
13695 main
13718 Jit thread pool worker thread 0
13724 Signal Catcher
13726 ADB-JDWP Connection Control Thread
13728 FinalizerDaemon
13729 FinalizerWatchdogDaemon
13727 ReferenceQueueDaemon
13730 HeapTaskDaemon
13732 Binder:13695_1
13733 Binder:13695_2
13736 Binder:13695_3
13895 Profile Saver
13909 Queue
13910 Queue
13911 Queue
13912 Queue
13913 Queue
13914 Queue
13916 Queue
13917 Queue
13915 Queue
13936 Answers Events Handler1
13937 queued-work-looper
13941 Crashlytics Exception Handler1
13950 StethoListener-main
13970 OkHttp ConnectionPool
13977 Binder:13695_4
13978 process reaper
13980 process reaper
14016 RenderThread
14023 Binder:13695_5
14026 Binder:13695_6
14021 Thread-16
14152 Thread-17
14153 Thread-18
14156 Studio:InputCon
14165 magnifier pixel copy result handler
14151 Thread-19
14435 RxIoScheduler-1 (Evictor)
14459 OkHttp ConnectionPool
14476 RealmFinalizingDaemon
14480 pool-3-thread-1
14481 pool-3-thread-2
14482 pool-3-thread-3
14483 pool-3-thread-4
14484 pool-3-thread-5
14487 pool-3-thread-6
14489 pool-3-thread-7
14490 pool-3-thread-8
14491 pool-3-thread-9
14602 glide-disk-cache-thread-0
14604 glide-source-thread-0
14614 Timer-1
14615 IntentService[]
14628 glide-source-thread-1
14630 OkHttp ConnectionPool
14633 glide-active-resources
14780 pool-3-thread-10
14788 Picasso-Stats
14789 Picasso-Dispatcher
14790 Picasso-refQueue
14805 Timer-3
14973 SpotScheduleThread
14974 PlaylistScheduleThread
14980 pool-3-thread-11
15000 pool-3-thread-12
15021 RxComputationScheduler-1
15025 RxComputationScheduler-2
15028 OkHttp ConnectionPool
15050 Timer-5
15052 pool-3-thread-13
15053 pool-3-thread-14
15767 pool-3-thread-15
15771 pool-3-thread-16
15772 pool-3-thread-17
*methods
0x18c8 java.lang.BootClassLoader getInstance ()Ljava/lang/BootClassLoader; ClassLoader.java
0x6ba0 java.lang.BootClassLoader findClass (Ljava/lang/String;)Ljava/lang/Class; ClassLoader.java
0x6b9c java.lang.BootClassLoader loadClass (Ljava/lang/String;Z)Ljava/lang/Class; ClassLoader.java
0x7878 java.lang.ClassLoader <init> (Ljava/lang/ClassLoader;)V ClassLoader.java
0x7880 java.lang.ClassLoader <init> (Ljava/lang/Void;Ljava/lang/ClassLoader;)V ClassLoader.java
Thanks in advance.
As I learned I can use Android Studio to see which process is taking more place on cpu and etc.
The only thing that I need to do is opening Profiler window then click the + button and Load from file. Then it will show the statistics of the .trace file.
Thanks!
Here's the code:
Observable.combineLatest(observable1, observable2,observable3, observable4,observable5,new Function5<>())
When one or sevral observables return code = 404,I throw exception
return Observable.error(
new RxApiException(tHttpResult.getCode(), tHttpResult.getMessage()));
And I will get
FATAL EXCEPTION : RxCachedThreadScheduler-3
How to solve this problem?
You need to define how you handle errors. If no onError handler is set up for the consumer of the Observable it gets forwarded to the Uncaught Exception Handler for the executing thread instead.
On android the exception handler causes a fatal exception when triggered, closing the application.
Either define a way that error should be handled or use RxJavaPlugins.registerErrorHandler(...) to define how unhandled exceptions should be processed for your entire application.
SO users, please read fully then decide to mark the Duplicate for NullPointer exception.
While app launch, from ApplicationExt(extends Application), we initialize the thread in which load the CSV file from Resource bundle(RawSource). It always works on many of the devices. But get crashed on below device for the very first time. For the second time, it gets loaded from the bundle.
OS version : Lollipop (5.1.1)
Device : OnePlus A0001
Crash Log:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference
at android.content.res.AssetManager.getResourceValue(AssetManager.java:213)
at android.content.res.Resources.getValue(Resources.java:1334)
at android.content.res.Resources.getValue(Resources.java:1323)
at android.content.res.Resources.openRawResource(Resources.java:1242)
at android.content.res.Resources.openRawResource(Resources.java:1219)
at com.xxxx.yyyy.network.NetworkManager.getBrandCodesFromCsvFile(NetworkManager.java:2961)
at com.xxxx.yyyy.network.NetworkManager.getBrandCodes(NetworkManager.java:3221)
at com.xxxx.yyyy.network.NetworkManager.checkAndUpdateMobileCodeFromBundle(NetworkManager.java:3110)
at com.xxxx.yyyy.OurApplication$1.run(OurApplication.java:132)
at java.lang.Thread.run(Thread.java:818)
Code Snippet:
In Application, onCreate(...),
Create a thread with code of csv load
Run the thread at the end of onCreate -> new Thread(ourThread).start();
Exact crash on this line :
InputStream bundleStream = OurApplicationClass.getContext().getResources().openRawResource(sourceId);
Note:
I've found related issue on Github. https://github.com/osmandapp/Osmand/issues/2575. But unable to confirm whether it's working for my case.