diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb867f5c..aba06a601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025) +## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v15.0.2...dev) + +### Added + +- Add new APIs to support NDK Crashes. ([#607](https://github.com/Instabug/Instabug-Flutter/pull/607)) + +## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025) ### Added @@ -20,7 +26,6 @@ - Bump Instabug Android SDK to v14.3.1 ([#577](https://github.com/Instabug/Instabug-Flutter/pull/577)). [See release notes](https://github.com/Instabug/Instabug-Android/releases/tag/v14.3.1). - ## [14.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v14.1.0...14.3.0) (April 21, 2025) ### Added diff --git a/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java b/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java index 075d0da69..8a1831959 100644 --- a/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java @@ -70,4 +70,12 @@ public void sendNonFatalError(@NonNull String jsonCrash, @Nullable Map MockReflected.crashReportException(any(JSONObject.class), eq(isHandled), eq(expectedUserAttributes), eq(expectedFingerprint), eq(expectedLevel))); } + + @Test + public void testSetNDKEnabledGivenTrue() { + boolean isEnabled = true; + + api.setNDKEnabled(isEnabled); + + mCrashReporting.verify(() -> CrashReporting.setNDKCrashesState(Feature.State.ENABLED)); + } + + @Test + public void testSetNDKEnabledGivenFalse() { + boolean isEnabled = false; + + api.setNDKEnabled(isEnabled); + + mCrashReporting.verify(() -> CrashReporting.setNDKCrashesState(Feature.State.DISABLED)); + } } diff --git a/ios/Classes/Modules/CrashReportingApi.m b/ios/Classes/Modules/CrashReportingApi.m index 0103aa766..fd06bb3cb 100644 --- a/ios/Classes/Modules/CrashReportingApi.m +++ b/ios/Classes/Modules/CrashReportingApi.m @@ -46,4 +46,9 @@ - (void)sendNonFatalErrorJsonCrash:(nonnull NSString *)jsonCrash userAttributes: userAttributes:userAttributes]; } + +- (void)setNDKEnabledIsEnabled:(nonnull NSNumber *)isEnabled error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +// This is auto-generated with pigeon, there is no NDK crashes for iOS. +} + @end diff --git a/lib/src/modules/crash_reporting.dart b/lib/src/modules/crash_reporting.dart index e5d0a0e3e..fe244caa2 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -116,4 +116,14 @@ class CrashReporting { ); return crashData; } + + /// Enables and disables NDK crash reporting. + /// [boolean] isEnabled + /// + /// Requires the [Instabug NDK package](https://pub.dev/packages/instabug_flutter_ndk) to be added to the project for this to work. + /// + /// This method is Android-only and has no effect on iOS. + static Future setNDKEnabled(bool isEnabled) async { + return _host.setNDKEnabled(isEnabled); + } } diff --git a/pigeons/crash_reporting.api.dart b/pigeons/crash_reporting.api.dart index 45f4a9cdb..4ac788e88 100644 --- a/pigeons/crash_reporting.api.dart +++ b/pigeons/crash_reporting.api.dart @@ -12,4 +12,6 @@ abstract class CrashReportingHostApi { String? fingerprint, String nonFatalExceptionLevel, ); + + void setNDKEnabled(bool isEnabled); } diff --git a/test/crash_reporting_test.dart b/test/crash_reporting_test.dart index a4ec87528..36afb7e37 100644 --- a/test/crash_reporting_test.dart +++ b/test/crash_reporting_test.dart @@ -83,4 +83,14 @@ void main() { ).called(1); } }); + + test('[setNDKEnabled] should call host method', () async { + const enabled = true; + + await CrashReporting.setNDKEnabled(enabled); + + verify( + mHost.setNDKEnabled(enabled), + ).called(1); + }); }