How to disable Crashlytics during development

后端 未结 28 2462
心在旅途
心在旅途 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:59

    This is silly answer, I know
    Just comment out Fabric.with(this, new Crashlytics());, work on that and uncomment it when you want to release it.

    0 讨论(0)
  • 2020-11-29 16:00

    Check out the latest doc. https://docs.fabric.io/android/crashlytics/build-tools.html#gradle-advanced-setup.

    Apart from adding ext.enableCrashlytics = false in build.grade you need to do,

    Crashlytics crashlyticsKit = new Crashlytics.Builder()
        .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
        .build();
    
    // Initialize Fabric with the debug-disabled crashlytics.
    Fabric.with(this, crashlyticsKit);
    
    0 讨论(0)
  • 2020-11-29 16:00

    Another simple solution that I like, because it doesn't require different manifest files:

    Step 1 - define manifest placeholders in build.gradle

    android {
        ...
        buildTypes {
            release {
                manifestPlaceholders = [crashlytics:"true"]
            }
            debug {
                manifestPlaceholders = [crashlytics:"false"]
            }
        }
        ...
    }
    

    Step 2 - use them in your AndroidManifest.xml

    <meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="${crashlytics}" />
    
    0 讨论(0)
  • 2020-11-29 16:03

    You can use a dedicated manifest file for debug mode (works for me with Crashlytics 2.9.7):

    Create the file app/src/debug/AndroidManifest.xml and add the following:

    <application>
    
        <meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="false"/>
    
    </application>
    

    Note that this meta-data element must be put into debug/AndroidManifest.xml only, and not into the regular AndroidManifest.xml

    The solution which uses CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build() did not work for me, and I found out that crashlytics is initialized by the CrashlyticsInitProvider before Application.onCreate() is called or an any activity is started, which means that manually initializing fabric in the application or an activity has no effect because fabric is already initialized.

    0 讨论(0)
  • 2020-11-29 16:04

    Up to date easiest version when using Gradle to build:

    if (!BuildConfig.DEBUG) {
        Fabric.with(this, new Crashlytics());
    }
    

    It uses the new Built-In Syntax from Fabric for Crashlytics and works automatically with the a Gradle build.

    0 讨论(0)
  • 2020-11-29 16:05
    1. Add this to your app’s build.gradle:

      android {
          buildTypes {
              debug {
                // Disable fabric build ID generation for debug builds
                ext.enableCrashlytics = false
                ...
      
    2. Disable the Crashlytics kit at runtime. Otherwise, the Crashlytics kit will throw the error:

      // Set up Crashlytics, disabled for debug builds
      // Add These lines in your app Application class onCreate method
      
      Crashlytics crashlyticsKit = new Crashlytics.Builder()
          .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
          .build();
      
      // Initialize Fabric with the debug-disabled crashlytics.
      Fabric.with(this, crashlyticsKit);
      
    3. In AndroidManifest.xml, add

      <meta-data
      android:name="firebase_crashlytics_collection_enabled"
      android:value="false" />
      
    0 讨论(0)
提交回复
热议问题