Comments (7)
Inside the Unity game loop I tried delaying stuff with
System.Threading.Thread.Sleep(6000);
but to no avail. Nothing gets triggered. Maybe blocking the Unity game loop does not cause ANRs?
Yeah, ANR triggers only when main
thread is blocked and Unity runs on Unity-Main
thread which is not main
))
To emulate an ANR you can use code:
public class AndroidShowStopper : MonoBehaviour
{
private static bool _stop;
public static void Stop()
{
_stop = true;
}
#if UNITY_ANDROID
void Update()
{
if (_stop)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("runOnUiThread", new AndroidJavaRunnable(runOnUiThread));
_stop= false;
}
}
void runOnUiThread()
{
Debug.Log("I'm running on the Java UI thread!");
while (true);
}
#endif
}
Just call AndroidShowStopper.Stop();
somewhere.
from anr-watchdog.
Okay, this is by design :(
Under the hood Crashlytics trims stack-traces longer then 1024 entries. ANRError collects all thread stacks as a single long stack-trace and it gets trimmed by Crashlytics.
So the solution is either crash with Fatal error to allow Crashlytics collect all threads or collect threads by ourselves and send it somewhere.
from anr-watchdog.
@AntonPetrov83 unrelated but would be cool if you could share your solution on how to use ANR-WatchDog with unity. Lots of people have now ANR issues since recently
from anr-watchdog.
@AntonPetrov83 unrelated but would be cool if you could share your solution on how to use ANR-WatchDog with unity. Lots of people have now ANR issues since recently
@mastef create a derived class from UnityPlayerActivity
like described here: Extending the UnityPlayerActivity Java Code
Then write something like that:
@Override protected void onCreate(Bundle savedInstanceState)
{
ANRWatchDog watchDog = new ANRWatchDog();
watchDog.setReportMainThreadOnly();
watchDog.start();
super.onCreate(savedInstanceState);
}
from anr-watchdog.
@AntonPetrov83 unrelated but would be cool if you could share your solution on how to use ANR-WatchDog with unity. Lots of people have now ANR issues since recently
@mastef create a derived class from
UnityPlayerActivity
like described here: Extending the UnityPlayerActivity Java CodeThen write something like that:
@Override protected void onCreate(Bundle savedInstanceState) { ANRWatchDog watchDog = new ANRWatchDog(); watchDog.setReportMainThreadOnly(); watchDog.start(); super.onCreate(savedInstanceState); }
Got there after writing the comment. But the setReportMainThreadOnly
is interesting! Thank you for the hint!
from anr-watchdog.
@AntonPetrov83 Thanks for the help! For future reference I'm adding the code here. Unfortunately I'm not able to trigger ANRs from Unity.
package com.mycompany.gamepackage;
import com.github.anrwatchdog.ANRError;
import com.github.anrwatchdog.ANRWatchDog;
import com.github.anrwatchdog.ANRWatchDog.ANRListener;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;
public class GameActivity extends UnityPlayerActivity
{
// Setup activity layout
@Override protected void onCreate(Bundle savedInstanceState)
{
Log.d("GameActivity", "WatchDog starting");
new ANRWatchDog(3000)
.setIgnoreDebugger(true)
.setReportMainThreadOnly()
.setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
Log.e("GameActivity", "", error);
Log.d("GameActivity", "ANR Caught");
}
})
.start();
Log.d("GameActivity", "WatchDog started");
super.onCreate(savedInstanceState);
}
}
This is confirmed working.
Inside the Unity game loop I tried delaying stuff with System.Threading.Thread.Sleep(6000);
but to no avail. Nothing gets triggered. Maybe blocking the Unity game loop does not cause ANRs?
from anr-watchdog.
Hi!
I integrated ANR-WatchDog to a Unity game using custom implementation of UnityPlayerActivity.
At first I released a game with the default behaviour of the ANR-WatchDog. My app crashed due to unhandled ANRError and Firebase Crashlytics recorded something around 40 threads at this moment including
UnityMain
thread and others. I usedsetReportMainThreadOnly()
because Crashlytics collects all threads by itself on fatal errors.Then I turned this crash to a non-fatal using this code:
@Override protected void onCreate(Bundle savedInstanceState) { ANRWatchDog watchDog = new ANRWatchDog(); watchDog.setANRListener(new ANRWatchDog.ANRListener() { @Override public void onAppNotResponding(ANRError error) { FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); crashlytics.recordException(error); } }); watchDog.start(); super.onCreate(savedInstanceState); }
This code records
ANRError
as a non-fatal exception and Crashlytics attaches stack traces contained inANRError
. That is why you do not seesetReportMainThreadOnly()
here any more. But now crash reports a very short, containing only 8-10 threads. What is strange there were noUnityMain
thread while this non-fatal was triggered in the middle of a gameplay.Please help, any ideas on how to get full list of stack traces attached?
How to integrate ANR-WatchDog to a Unity game using custom implementation of UnityPlayerActivity?
from anr-watchdog.
Related Issues (20)
- Debug.waitForDebugger() conflict HOT 1
- Few queries - Not exactly issue HOT 1
- How can I get pid of Thread from ANRErro? HOT 1
- Anr is not being detected for android 8.0 HOT 1
- Real ANR timeout HOT 2
- Ggv
- Mm
- I too was having this issue earlier, it seems when you Log a non-runtime exception in crashlytics it creates nonfatal exceptions in fabric dashboard since ANRs don't necessarily crash an application. You need to toggle the switch in the fabric dashboard to show all exceptions including non-fatals as by default it only shows fatal exceptions.
- ANRError indeed is too big for Crashlytics. I convert errors into text files and upload to Firebase storage it is free and you can setup it from Android Studio.
- The fix is released in version `1.4.0`.
- Cannot download version 1.4.0 HOT 2
- 10786c7b4e6270fb3a65a89082a6581e8250e1f6
- It seems not so good to start the anr-watchdog on application oncreate
- Main thread is in runnable state but still ANR is detected. HOT 1
- Support for getStackTrace() and setStackTrace() HOT 1
- Race condition for _tick and _reported
- Set Thread priority below main thread.
- anr debug exception please help me
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anr-watchdog.