How to disable Crashlytics during development

后端 未结 28 2607
心在旅途
心在旅途 2020-11-29 15:42

Is there any simple way to turn Crashlytics Android SDK off while developing ?

I don\'t want it to send a crash every time I do something stupid

On the othe

28条回答
  •  囚心锁ツ
    2020-11-29 15:47

    2020 Post Fabric Answer

    Paste the code below in your Application class and call the method setCrashlyticsState from your application onCreate. You may optionally add your test device Ids to the debugDevices HashSet too so that your personal devices can be ignored, even when building in release mode.

    Note. The device id returned by Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); is not guaranteed to be unique or constant (It can change on a factory reset or manually on a rooted device). But it should be good enough.

    private final HashSet debugDevices = new HashSet(Arrays.asList("6a3d5c2bae3fd32c"));
    
    private boolean isDebugDevice(String deviceId) {
        return debugDevices.contains(deviceId);
    }
    
    private void setCrashlyticsState() {
        @SuppressLint("HardwareIds")
        String deviceId = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
        if (BuildConfig.DEBUG || isDebugDevice(deviceId)) {
            Log.v("DeviceId", deviceId);
            FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
        }
    }
    

    Check that BuildConfig. is looking at the correct BuildConfig class. There are often several options and the wrong one could be dragged in.

提交回复
热议问题