From 4a3d57f2b95ed028f191821a9d94cef30c3df330 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 22 Jul 2025 03:09:29 +0300 Subject: [PATCH 1/7] feat: add NDK crash reporting APIs --- .../instabug/flutter/modules/CrashReportingApi.java | 8 ++++++++ lib/src/modules/crash_reporting.dart | 11 +++++++++++ pigeons/crash_reporting.api.dart | 2 ++ 3 files changed, 21 insertions(+) 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 setNDKEnabled(bool isEnabled) async { + if (Platform.isAndroid) { + 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); } From 9a15a94beb288117aba94f5c474cc438481cedde Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Mon, 28 Jul 2025 12:30:17 +0300 Subject: [PATCH 2/7] chore: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb867f5c..d6261b180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v15.0.2...dev) + +### Added + +- Add new APIs to support NDK Crashes. + ## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025) ### Added From 23e9de25bdcc14e8b6f1eee1c7b9defdeec86263 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Mon, 28 Jul 2025 12:41:35 +0300 Subject: [PATCH 3/7] fix: add iOS stub APIs --- ios/Classes/Modules/CrashReportingApi.m | 5 +++++ 1 file changed, 5 insertions(+) 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 From c77a12733a3a068a86ee23d10b7de009736613d5 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Mon, 28 Jul 2025 12:52:49 +0300 Subject: [PATCH 4/7] chore: update changelog --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6261b180..aba06a601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ ### Added -- Add new APIs to support NDK Crashes. +- 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) +## [15.0.2](https://github.com/Instabug/Instabug-Flutter/compare/v14.3.0...15.0.2) (Jul 7, 2025) ### Added @@ -26,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 From 5fcad06ea7040d83f81cb5d70667dbd9fb1dc4b0 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 5 Aug 2025 15:51:01 +0300 Subject: [PATCH 5/7] test: add NDK enabled tests for CrashReporting API - Implemented unit tests for `setNDKEnabled` method in both Java and Dart. - Verified that enabling and disabling NDK crash reporting calls the appropriate host methods. --- .../flutter/CrashReportingApiTest.java | 18 ++++++++++++++++++ test/crash_reporting_test.dart | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java b/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java index a538fc8b4..b33fed840 100644 --- a/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java +++ b/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java @@ -98,4 +98,22 @@ public void testSendNonFatalError() { reflected.verify(() -> 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/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); + }); } From 612efb69e019cd96d1999f595a6b6b93816081e5 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 5 Aug 2025 17:37:25 +0300 Subject: [PATCH 6/7] fix: remove platfrom check from NDK API --- lib/src/modules/crash_reporting.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/modules/crash_reporting.dart b/lib/src/modules/crash_reporting.dart index 829175fae..ff612ee74 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -122,9 +122,9 @@ class CrashReporting { /// [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 { - if (Platform.isAndroid) { - return _host.setNDKEnabled(isEnabled); - } + return _host.setNDKEnabled(isEnabled); } } From 6f1ae20d079da21d7a1db9094795d1cf43b42924 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 5 Aug 2025 23:57:41 +0300 Subject: [PATCH 7/7] chore: fix dart lint --- lib/src/modules/crash_reporting.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/modules/crash_reporting.dart b/lib/src/modules/crash_reporting.dart index ff612ee74..fe244caa2 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:instabug_flutter/src/generated/crash_reporting.api.g.dart';