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?
Related
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!
I'm building a React Native 0.57 app, which works fine on IOS but fails on Android with the following error:
Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.
throwOnInvalidObjectType ReactNativeRenderer-dev.js:8779:6
reconcileChildFibers ReactNativeRenderer-dev.js:9842:31
reconcileChildren ReactNativeRenderer-dev.js:10319:6
updateHostRoot ReactNativeRenderer-dev.js:10683:6
beginWork ReactNativeRenderer-dev.js:11360:28
performUnitOfWork ReactNativeRenderer-dev.js:14091:21
workLoop ReactNativeRenderer-dev.js:14129:41
renderRoot ReactNativeRenderer-dev.js:14226:15
performWorkOnRoot ReactNativeRenderer-dev.js:15193:17
performWork ReactNativeRenderer-dev.js:15090:24
performSyncWork ReactNativeRenderer-dev.js:15047:14
requestWork ReactNativeRenderer-dev.js:14925:19
scheduleWork ReactNativeRenderer-dev.js:14711:16
scheduleRootUpdate ReactNativeRenderer-dev.js:15429:15
updateContainerAtExpirationTime ReactNativeRenderer-dev.js:15462:28
updateContainer ReactNativeRenderer-dev.js:15494:4
render ReactNativeRenderer-dev.js:16142:20
renderApplication renderApplication.js:59:34
run AppRegistry.js:101:10
runApplication AppRegistry.js:195:26
__callFunction MessageQueue.js:349:47
<unknown> MessageQueue.js:106:26
__guard MessageQueue.js:297:10
callFunctionReturnFlushedQueue MessageQueue.js:105:17
I searched on the Internet et SO (of course), and everybody is talking about firebase which I'm not using.
As far as I remember, with RN 0.56 all was working fine, and since the upgrade to 0.57, this error started to occur.
The workaround is to enable the debugger ... but the release is suffering the same issue.
The issue is happening in the simulator and on the real device.
As the app is working on IOS, I guess this is coming from the android project.
How can I investigate this issue?
UPDATE
I found out that adding import 'core-js' to the top of the index.js file of the app is avoiding the error.
This core-js is a dependency of many package, like react-native itself.
Why is this import solving the issue and why do I have to do it, especially if the iOS version works fine?
There is a crash that is showing up repeatedly in Firebase crash reporting for my React Native Android app. However, I am at a loss as to what would be causing it, as the stack trace doesn't cite any of my code. Does anyone know what might be the cause? I am on React Native 0.47.1
The stack trace is as follows:
Exception java.lang.RuntimeException: java.lang.InterruptedException
com.facebook.react.common.futures.SimpleSettableFuture.getOrThrow (SimpleSettableFuture.java:102)
com.facebook.react.bridge.queue.MessageQueueThreadImpl.startNewBackgroundThread (MessageQueueThreadImpl.java:199)
com.facebook.react.bridge.queue.MessageQueueThreadImpl.create (MessageQueueThreadImpl.java:146)
com.facebook.react.bridge.queue.ReactQueueConfigurationImpl.create (ReactQueueConfigurationImpl.java:87)
com.facebook.react.bridge.CatalystInstanceImpl.<init> (CatalystInstanceImpl.java:101)
com.facebook.react.bridge.CatalystInstanceImpl.<init> (CatalystInstanceImpl.java:42)
com.facebook.react.bridge.CatalystInstanceImpl$Builder.build (CatalystInstanceImpl.java:574)
com.facebook.react.ReactInstanceManager.createReactContext (ReactInstanceManager.java:999)
com.facebook.react.ReactInstanceManager.access$600 (ReactInstanceManager.java:109)
com.facebook.react.ReactInstanceManager$4.run (ReactInstanceManager.java:802)
java.lang.Thread.run (Thread.java:761)
Caused by java.lang.InterruptedException:
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1301)
java.util.concurrent.CountDownLatch.await (CountDownLatch.java:203)
com.facebook.react.common.futures.SimpleSettableFuture.get (SimpleSettableFuture.java:66)
com.facebook.react.common.futures.SimpleSettableFuture.getOrThrow (SimpleSettableFuture.java:100)
com.facebook.react.bridge.queue.MessageQueueThreadImpl.startNewBackgroundThread (MessageQueueThreadImpl.java:199)
com.facebook.react.bridge.queue.MessageQueueThreadImpl.create (MessageQueueThreadImpl.java:146)
com.facebook.react.bridge.queue.ReactQueueConfigurationImpl.create (ReactQueueConfigurationImpl.java:87)
com.facebook.react.bridge.CatalystInstanceImpl.<init> (CatalystInstanceImpl.java:101)
com.facebook.react.bridge.CatalystInstanceImpl.<init> (CatalystInstanceImpl.java:42)
com.facebook.react.bridge.CatalystInstanceImpl$Builder.build (CatalystInstanceImpl.java:574)
com.facebook.react.ReactInstanceManager.createReactContext (ReactInstanceManager.java:999)
com.facebook.react.ReactInstanceManager.access$600 (ReactInstanceManager.java:109)
com.facebook.react.ReactInstanceManager$4.run (ReactInstanceManager.java:802)
java.lang.Thread.run (Thread.java:761)
This problem also occur for many others as well and the cause is various. You can find the discussion about it here. Since I really don't know what your app does so here is some possible reasons:
You're using react-native-navigation (you can try change it back to react-navigation)
You're using react-native-image-crop-picker or react-native-image-picker (Which produce the same error that make your app crash on some device and it throw InterruptedException
If the problem is number 2 you can try to fix it by alter MainApplication.java:
#Override
public boolean clearHostOnActivityDestroy() {
return false;
}
The fix in number 2 was also reference from here under acintyo answer.
As for changing the react-native version you can try it but I do not recommend it since after reading through the issues mentioned above, I saw that many version also experienced this issues (most of them are 0.49.+ or 0.45.x)
My Android App reported some crash report:
java.lang.NoSuchMethodError: android.app.ANRAppManager.dumpMessageHistory
at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1177)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:609)
at android.os.Binder.execTransact(Binder.java:351)
at dalvik.system.NativeStart.run(Native Method)
A lot of android device reported the same crash:
Android|Android=>3
android|Coolpad=>1
Android|Lenovo=>1
Android|VIVO=>2
apsl|Lenovo=>1
apsl|Samsung=>2
ARES|AE912=>3
Coolpad|Coolpad=>2
COWW|C920=>5
GoDonie|GoDonie F7=>1
HESM|HSEM TD777=>2
HMI|H2=>1
huawei|huawei=>2
intki|intki_E86=>3
ioco|i9100 X6=>1
Lenovo|Lenovo A820T=>1
MEEG|MEEG_101M=>2
NEWLAND|N003=>2
SAST|SAST YC500=>1
But I didn't find "dumpMessageHistory" in my code, please help, thanks!!
The class android.app.ANRAppManager can not be found in Android Application Framework (/frameworks/base/core/java/android/app). Probably it is a vendor supplied class for MTK chips. Whenever there is an ANR raised, ANRAppManager.dumpMessageHistory would be invoked.
The best advice would be to keep track of all cases of ANR that takes place in your app and try to fix it.
Documentation for the Google Cloud MBS states that access to stored Entities can be controlled via prefixing the KindName of that entity with strings "[public]" or "[private]" (or nothing).
https://cloud.google.com/developers/articles/mobile-backend-starter-api-reference#acfce
However attempting insertion of CloudEntities into the Datastore using KindNames that start with [public] or [private] causes an exception/error, specifically that the KindName is invalid.
This is the case both for the Backend running in Open and in Secured mode (using Google login credentials to derive the _owner field)
e.g. here I use KindName "[public]TestDB" which fails, whereas "TestDB" would not throw any exception.
04-22 19:57:54.132: E/AndroidRuntime(4690): Process: com.example.package, PID: 4690
04-22 19:57:54.132: E/AndroidRuntime(4690): java.lang.IllegalArgumentException: Illegal kind name: [public]TestDB
04-22 19:57:54.132: E/AndroidRuntime(4690): at com.google.cloud.backend.core.CloudEntity.(CloudEntity.java:86)
04-22 19:57:54.132: E/AndroidRuntime(4690): at com.example.package.CloudUtil.convertUpdatesToCEList(CloudUtil.java:252)
04-22 19:57:54.132: E/AndroidRuntime(4690): at com.example.package.CloudUtil.checkSync(CloudUtil.java:199)
The relevant section of code editted/compressed for brevity is:
CloudBackendMessaging cbm=_cloudfrag.getCloudBackend();
List<CloudEntity> entries=new ArrayList<CloudEntity>();
while (...) {
CloudEntity ce=new CloudEntity(_CLOUD_DB_KIND);
ce.put("fieldname", devID);
entries.add(ce);
}
_countActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
cbm.updateAll(entries, handler);
}
});
Where handler is the callback and _cloudfrag is the CloudBackendFragment from the sample code.
I get the same effect using both inserts and updates, for single or multiple i.e. lists of entities at a time.
I can only think I'm misunderstanding the documentation - but it seems fairly explicit that KindNames can begin with [public] [private] etc?
Judging by the bug reports on github from others experiencing the same issue, this is a bug in Google's MBS library.
Unfortunately the response to this has been silence for months until tonight the devs posted a single commit updating the readme file to indicate this library is no longer supported and is not an official google product (despite it being pushed as a starter kit with every cloud project started from the console!).
https://github.com/GoogleCloudPlatform/solutions-mobile-backend-starter-android-client/pull/16
Looking at the source I think this access modifier feature was never actually implemented despite documentation to the contrary.